Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge commit '045db1657e870c721be490b411868f4181a12ced' into surf++
authorPaul Bédaride <paul.bedaride@gmail.com>
Wed, 30 Oct 2013 14:26:47 +0000 (15:26 +0100)
committerPaul Bédaride <paul.bedaride@gmail.com>
Wed, 30 Oct 2013 14:26:47 +0000 (15:26 +0100)
Conflicts:
buildtools/Cmake/DefinePackages.cmake
src/include/surf/datatypes.h
src/include/surf/surf.h
src/simgrid/sg_config.c
src/simix/smx_io.c
src/simix/smx_smurf_private.h
src/surf/cpu_cas01.c
src/surf/cpu_ti.c
src/surf/network.c
src/surf/network_constant.c
src/surf/network_gtnets.c
src/surf/new_model.c
src/surf/storage.c
src/surf/storage_private.h
src/surf/surf.c
src/surf/surf_action.c
src/surf/surf_model.c
src/surf/surf_routing.cpp
src/surf/surf_routing_cluster.c
src/surf/surf_routing_floyd.cpp
src/surf/surf_routing_full.cpp
src/surf/surf_routing_none.c
src/surf/surf_routing_vivaldi.c
src/surf/workstation.c
src/surf/workstation_ptask_L07.c

65 files changed:
1  2 
CMakeLists.txt
buildtools/Cmake/DefinePackages.cmake
include/msg/datatypes.h
include/simgrid/platf.h
include/surf/surf_routing.h
include/xbt/heap.h
include/xbt/module.h
src/include/simgrid/platf_interface.h
src/include/simgrid/sg_config.h
src/include/surf/datatypes.h
src/include/surf/maxmin.h
src/include/surf/surf.h
src/include/surf/surf_resource.h
src/include/surf/surf_resource_lmm.h
src/include/surf/trace_mgr.h
src/instr/instr_interface.c
src/instr/instr_private.h
src/simdag/sd_global.c
src/simdag/sd_link.c
src/simdag/sd_task.c
src/simdag/sd_workstation.c
src/simgrid/sg_config.c
src/simix/smx_global.c
src/simix/smx_host.c
src/simix/smx_host_private.h
src/simix/smx_io.c
src/simix/smx_network.c
src/simix/smx_new_api.c
src/simix/smx_process.c
src/simix/smx_smurf_private.h
src/simix/smx_synchro.c
src/surf/cpu.cpp
src/surf/cpu.hpp
src/surf/cpu_cas01.cpp
src/surf/cpu_cas01.hpp
src/surf/cpu_ti.cpp
src/surf/cpu_ti.hpp
src/surf/instr_routing.c
src/surf/instr_surf.c
src/surf/network.cpp
src/surf/network_constant.cpp
src/surf/network_smpi.cpp
src/surf/storage.cpp
src/surf/storage.hpp
src/surf/storage_private.h
src/surf/surf.cpp
src/surf/surf.hpp
src/surf/surf_interface.cpp
src/surf/surf_private.h
src/surf/surf_routing.cpp
src/surf/surf_routing_dijkstra.cpp
src/surf/surf_routing_floyd.cpp
src/surf/surf_routing_full.cpp
src/surf/surf_routing_generic.cpp
src/surf/surf_routing_private.h
src/surf/surfxml_parse.c
src/surf/workstation.cpp
src/surf/workstation.hpp
src/surf/workstation_ptask_L07.cpp
src/surf/workstation_ptask_L07.hpp
src/xbt/log.c
src/xbt/swag.c
teshsuite/simdag/platforms/flatifier.c
testsuite/surf/surf_usage.c
testsuite/surf/surf_usage2.c

diff --combined CMakeLists.txt
@@@ -7,9 -7,6 +7,9 @@@ project(SimGrid C
  if (enable_gtnets OR enable_ns3)
    enable_language(CXX)
  endif()
 +
 +enable_language(CXX)
 +
  if (NOT DEFINED enable_smpi OR enable_smpi) # smpi is enabled by default
    # Call enable_language(Fortran) in order to load the build rules for
    # this language, needed by teshsuite/smpi/mpich-test/.  Use
@@@ -35,7 -32,7 +35,7 @@@
  endif()
  
  set(CMAKE_C_FLAGS "" CACHE TYPE INTERNAL FORCE)
 -set(CMAKE_CXX_FLAGS "" CACHE TYPE INTERNAL FORCE)
 +set(CMAKE_CXX_FLAGS " -std=c++11 " CACHE TYPE INTERNAL FORCE)
  set(CMAKE_EXE_LINKER_FLAGS "" CACHE TYPE INTERNAL FORCE)
  set(CMAKE_C_LINK_FLAGS "" CACHE TYPE INTERNAL FORCE)
  set(CMAKE_Fortran_FLAGS "" CACHE TYPE INTERNAL FORCE)
@@@ -48,11 -45,13 +48,13 @@@ set(CMAKE_Fortran_LINK_FLAGS "" CACHE T
  # 3.7.{0,1} -> release 3.7, 3.7.1
  # 3.8.{0,1} -> release 3.8, 3.8.1
  # 3.9.0 -> release 3.9
+ # 3.9.90 -> release 3.10pre1
  # 3.10.0 -> release 3.10
  
  set(SIMGRID_VERSION_MAJOR "3")
- set(SIMGRID_VERSION_MINOR "10")
- set(SIMGRID_VERSION_PATCH "0")
+ set(SIMGRID_VERSION_MINOR "9")
+ set(SIMGRID_VERSION_PATCH "90")
  
  if(${SIMGRID_VERSION_PATCH} EQUAL "0")
    set(release_version "${SIMGRID_VERSION_MAJOR}.${SIMGRID_VERSION_MINOR}")
@@@ -77,8 -76,7 +79,7 @@@ else(
    endif()
  endif()
  
- string(REGEX MATCH "gcc" GCC "${CMAKE_C_COMPILER}")
- if(GCC)
+ if(${CMAKE_C_COMPILER_ID} STREQUAL "GNU")
    exec_program("${CMAKE_C_COMPILER} --version" OUTPUT_VARIABLE "COMPILER_C_VERSION")
    exec_program("${CMAKE_CXX_COMPILER} --version" OUTPUT_VARIABLE "COMPILER_CXX_VERSION")
    string(REGEX MATCH "[0-9].[0-9].[0-9]" COMPILER_C_VERSION "${COMPILER_C_VERSION}")
@@@ -194,10 -192,6 +195,6 @@@ endif(
  
  include_directories(${INCLUDES})
  
- ### Determine the assembly flavor that we need today
- include(CMakeDetermineSystem)
- set(PROCESSOR_${CMAKE_SYSTEM_PROCESSOR} 1)
  ### Setup Options
  include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/Option.cmake)
  
@@@ -209,9 -203,7 +206,7 @@@ include(${CMAKE_HOME_DIRECTORY}/buildto
  
  ### Build some Maintainer files
  include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/MaintainerMode.cmake)
- if(NOT WIN32)
-   include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/UnitTesting.cmake)
- endif()
+ include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/UnitTesting.cmake)
  
  ### Setup gcc flags
  include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/Flags.cmake)
@@@ -10,7 -10,7 +10,7 @@@ set(EXTRA_DIS
    src/include/simgrid/sg_config.h
    src/include/smpi/smpi_interface.h
    src/include/surf/datatypes.h
-   src/include/surf/maxmin.h 
+   src/include/surf/maxmin.h
    src/include/surf/random_mgr.h
    src/include/surf/surf.h
    src/include/surf/surf_resource.h
    src/simix/smx_smurf_private.h
    src/simix/smx_synchro_private.h
    src/smpi/README
 +  src/smpi/colls/COPYRIGHTS
    src/smpi/colls/colls.h
    src/smpi/colls/colls_private.h
    src/smpi/colls/coll_tuned_topo.h
    src/smpi/private.h
    src/smpi/smpi_mpi_dt_private.h
 -  src/surf/cpu_cas01_private.h
 +  src/surf/cpu.hpp
 +  src/surf/cpu_ti.hpp
 +  src/surf/cpu_cas01.hpp
    src/surf/cpu_ti_private.h
    src/surf/gtnets/gtnets_interface.h
    src/surf/gtnets/gtnets_simulator.h
    src/surf/gtnets/gtnets_topology.h
    src/surf/maxmin_private.h
-   #src/surf/network_gtnets_private.h
 -  src/surf/network_gtnets_private.h
 +  src/surf/network_gtnets.hpp
    src/surf/network_ns3_private.h
    src/surf/network_private.h
 +  src/surf/network.hpp
 +  src/surf/network_smpi.hpp
 +  src/surf/network_constant.hpp
    src/surf/ns3/my-point-to-point-helper.h
    src/surf/ns3/ns3_interface.h
    src/surf/ns3/ns3_simulator.h
    src/surf/platf_generator_private.h
    src/surf/simgrid.dtd
    src/surf/simgrid_dtd.c
 +  src/surf/storage.hpp
    src/surf/storage_private.h
 +  src/surf/surf.hpp
    src/surf/surf_private.h
    src/surf/surf_routing_private.h
 +  src/surf/surf_routing_private.hpp
 +  src/surf/surf_routing.hpp
 +  src/surf/surf_routing_cluster.hpp
 +  src/surf/surf_routing_dijkstra.hpp
 +  src/surf/surf_routing_floyd.hpp
 +  src/surf/surf_routing_full.hpp
 +  src/surf/surf_routing_generic.hpp
 +  src/surf/surf_routing_none.hpp
 +  src/surf/surf_routing_vivaldi.hpp
    src/surf/surfxml_parse.c
    src/surf/trace_mgr_private.h
 +  src/surf/workstation.hpp
 +  src/surf/workstation_ptask_L07.hpp
    src/win32/config.h
    src/xbt/automaton/automaton_lexer.yy.c
    src/xbt/automaton/parserPromela.lex
@@@ -139,7 -119,6 +138,6 @@@ set(SMPI_SR
    src/smpi/colls/allgather-bruck.c
    src/smpi/colls/allgather-GB.c
    src/smpi/colls/allgather-loosely-lr.c
-   src/smpi/colls/allgather-lr.c
    src/smpi/colls/allgather-NTSLR.c
    src/smpi/colls/allgather-NTSLR-NB.c
    src/smpi/colls/allgather-pair.c
    src/smpi/colls/allgatherv-ompi-neighborexchange.c
    src/smpi/colls/allgatherv-ompi-bruck.c
    src/smpi/colls/allgatherv-mpich-rdb.c
+   src/smpi/colls/allgatherv-mpich-ring.c
    src/smpi/colls/allreduce-lr.c
-   src/smpi/colls/allreduce-NTS.c
    src/smpi/colls/allreduce-rab1.c
    src/smpi/colls/allreduce-rab2.c
    src/smpi/colls/allreduce-rab-rdb.c
-   #src/smpi/colls/allreduce-rab-reduce-scatter.c
-   src/smpi/colls/allreduce-rab-rsag.c
    src/smpi/colls/allreduce-rdb.c
    src/smpi/colls/allreduce-redbcast.c
    src/smpi/colls/allreduce-smp-binomial.c
    src/smpi/colls/allreduce-ompi-ring-segmented.c
    src/smpi/colls/alltoall-2dmesh.c
    src/smpi/colls/alltoall-3dmesh.c
  #src/smpi/colls/alltoall-bruck.c
#  src/smpi/colls/alltoall-bruck.c
    src/smpi/colls/alltoall-pair.c
    src/smpi/colls/alltoall-pair-light-barrier.c
    src/smpi/colls/alltoall-pair-mpi-barrier.c
    src/smpi/colls/alltoall-ring-light-barrier.c
    src/smpi/colls/alltoall-ring-mpi-barrier.c
    src/smpi/colls/alltoall-ring-one-barrier.c
-   src/smpi/colls/alltoall-simple.c
    src/smpi/colls/alltoallv-pair.c   
    src/smpi/colls/alltoallv-pair-light-barrier.c
    src/smpi/colls/alltoallv-pair-mpi-barrier.c
    src/smpi/colls/alltoallv-ring-mpi-barrier.c
    src/smpi/colls/alltoallv-ring-one-barrier.c
    src/smpi/colls/alltoallv-bruck.c
-   src/smpi/colls/bcast-arrival-nb.c
+   src/smpi/colls/alltoallv-ompi-basic-linear.c
    src/smpi/colls/bcast-arrival-pattern-aware.c
    src/smpi/colls/bcast-arrival-pattern-aware-wait.c
    src/smpi/colls/bcast-arrival-scatter.c
    src/smpi/colls/gather-ompi.c
    src/smpi/colls/reduce_scatter-ompi.c
    src/smpi/colls/reduce_scatter-mpich.c
+   src/smpi/colls/smpi_automatic_selector.c
    src/smpi/colls/scatter-ompi.c
    src/smpi/colls/barrier-ompi.c
    )
@@@ -290,7 -267,7 +286,7 @@@ set(GTNETS_SR
    src/surf/gtnets/gtnets_interface.cc
    src/surf/gtnets/gtnets_simulator.cc
    src/surf/gtnets/gtnets_topology.cc
 -  src/surf/network_gtnets.c
 +  src/surf/network_gtnets.cpp
    )
  
  set(NS3_SRC
    )
  
  set(SURF_SRC
 -  src/surf/cpu_cas01.c
 -  src/surf/cpu_ti.c
 +  src/surf/cpu.cpp
 +  src/surf/cpu_ti.cpp
 +  src/surf/cpu_cas01.cpp
    src/surf/fair_bottleneck.c
    src/surf/instr_routing.c
    src/surf/instr_surf.c
    src/surf/lagrange.c
    src/surf/maxmin.c
 -  src/surf/network.c
 -  src/surf/network_constant.c
 +  src/surf/network.cpp
 +  src/surf/network_smpi.cpp  
 +  src/surf/network_constant.cpp
    src/surf/platf_generator.c
    src/surf/random_mgr.c
    src/surf/sg_platf.c
 -  src/surf/storage.c
 -  src/surf/surf.c
 -  src/surf/surf_action.c
 -  src/surf/surf_model.c
 -  src/surf/surf_routing.c
 -  src/surf/surf_routing_cluster.c
 -  src/surf/surf_routing_dijkstra.c
 -  src/surf/surf_routing_floyd.c
 -  src/surf/surf_routing_full.c
 -  src/surf/surf_routing_generic.c
 -  src/surf/surf_routing_none.c
 -  src/surf/surf_routing_vivaldi.c
 +  src/surf/storage.cpp
 +  src/surf/surf.cpp
 +  src/surf/surf_interface.cpp
 +  src/surf/surf_routing.cpp  
 +  src/surf/surf_routing_cluster.cpp
 +  src/surf/surf_routing_dijkstra.cpp
 +  src/surf/surf_routing_floyd.cpp
 +  src/surf/surf_routing_full.cpp
 +  src/surf/surf_routing_generic.cpp
 +  src/surf/surf_routing_none.cpp
 +  src/surf/surf_routing_vivaldi.cpp
    src/surf/surfxml_parse.c
    src/surf/surfxml_parseplatf.c
    src/surf/trace_mgr.c
 -  src/surf/workstation.c
 -  src/surf/workstation_ptask_L07.c
 +  src/surf/workstation.cpp
 +  src/surf/workstation_ptask_L07.cpp
    src/xbt/xbt_sg_stubs.c
    )
  
@@@ -395,9 -371,11 +391,9 @@@ set(SIMIX_SR
  
  set(SURF_SRC
    ${SURF_SRC}
 -  src/surf/new_model.c
    )
  set(EXTRA_DIST
    ${EXTRA_DIST}
 -  src/surf/new_model_private.h
    )
  #* ****************************************************************************************** *#
  
@@@ -556,7 -534,6 +552,6 @@@ set(headers_to_instal
    include/simgrid/platf_generator.h
    include/simgrid/simix.h
    include/smpi/mpi.h
-   include/smpi/mpif.h
    include/smpi/smpi.h
    include/smpi/smpi_cocci.h
    include/smpi/smpi_main.h
    )
  set(source_of_generated_headers
    include/simgrid_config.h.in
+   include/smpi/mpif.h.in
    include/smpi/smpif.h.in
    src/context_sysv_config.h.in)
  
@@@ -726,7 -704,6 +722,6 @@@ else(
  endif()
  
  set(DOC_SOURCES
-   doc/AS_hierarchy.png
    doc/Doxyfile.in
    doc/Layout.xml
    doc/sg_thread_model.fig
    doc/msg-tuto-src/platforms/griffon.xml
    doc/msg-tuto-src/platforms/peers.xml
    doc/msg-tuto-src/platforms/platform.xml
+   
+   CITATION.bib
    )
  
  set(DOC_FIGS
@@@ -808,6 -787,7 +805,7 @@@ set(DOC_TOOL
  set(DOC_IMG
    ${CMAKE_HOME_DIRECTORY}/doc/simgrid.css
    ${CMAKE_HOME_DIRECTORY}/doc/sc3-description.png
+   ${CMAKE_HOME_DIRECTORY}/doc/webcruft/AS_hierarchy.png
    ${CMAKE_HOME_DIRECTORY}/doc/webcruft/Paje_MSG_screenshot.jpg
    ${CMAKE_HOME_DIRECTORY}/doc/webcruft/Paje_MSG_screenshot_thn.jpg
    ${CMAKE_HOME_DIRECTORY}/doc/webcruft/SGicon.gif
    ${CMAKE_HOME_DIRECTORY}/doc/webcruft/win_install_04.png
    ${CMAKE_HOME_DIRECTORY}/doc/webcruft/win_install_05.png
    ${CMAKE_HOME_DIRECTORY}/doc/webcruft/win_install_06.png
+   ${CMAKE_HOME_DIRECTORY}/doc/webcruft/smpi_simgrid_alltoall_pair_16.png
+   ${CMAKE_HOME_DIRECTORY}/doc/webcruft/smpi_simgrid_alltoall_ring_16.png
    )
  
  set(bin_files
@@@ -879,6 -861,9 +879,9 @@@ set(EXAMPLES_CMAKEFILES_TX
    examples/msg/chainsend/CMakeLists.txt
    examples/msg/chord/CMakeLists.txt
    examples/msg/cloud/CMakeLists.txt
+   examples/msg/energy/e1/CMakeLists.txt
+   examples/msg/energy/e2/CMakeLists.txt
+   examples/msg/energy/e3/CMakeLists.txt
    examples/msg/gpu/CMakeLists.txt
    examples/msg/gtnets/CMakeLists.txt
    examples/msg/icomms/CMakeLists.txt
    examples/simdag/dax/CMakeLists.txt
    examples/simdag/dot/CMakeLists.txt
    examples/simdag/goal/CMakeLists.txt
+   examples/simdag/io/CMakeLists.txt
    examples/simdag/metaxml/CMakeLists.txt
    examples/simdag/properties/CMakeLists.txt
    examples/simdag/scheduling/CMakeLists.txt
    )
  
  set(TESHSUITE_CMAKEFILES_TXT
-   teshsuite/CMakeLists.txt
    teshsuite/msg/CMakeLists.txt
+   teshsuite/msg/storage/CMakeLists.txt
    teshsuite/msg/trace/CMakeLists.txt
    teshsuite/simdag/CMakeLists.txt
    teshsuite/simdag/availability/CMakeLists.txt
    teshsuite/simdag/network/p2p/CMakeLists.txt
    teshsuite/simdag/partask/CMakeLists.txt
    teshsuite/simdag/platforms/CMakeLists.txt
+   teshsuite/simix/CMakeLists.txt
    teshsuite/smpi/CMakeLists.txt
-   teshsuite/smpi/mpich-test/CMakeLists.txt
-   teshsuite/smpi/mpich-test/coll/CMakeLists.txt
-   teshsuite/smpi/mpich-test/context/CMakeLists.txt
-   teshsuite/smpi/mpich-test/env/CMakeLists.txt
-   teshsuite/smpi/mpich-test/profile/CMakeLists.txt
-   teshsuite/smpi/mpich-test/pt2pt/CMakeLists.txt
+   teshsuite/smpi/mpich3-test/CMakeLists.txt
+   teshsuite/smpi/mpich3-test/attr/CMakeLists.txt
+   teshsuite/smpi/mpich3-test/comm/CMakeLists.txt
+   teshsuite/smpi/mpich3-test/coll/CMakeLists.txt
+   teshsuite/smpi/mpich3-test/datatype/CMakeLists.txt
+   teshsuite/smpi/mpich3-test/group/CMakeLists.txt
+   teshsuite/smpi/mpich3-test/init/CMakeLists.txt
+   teshsuite/smpi/mpich3-test/pt2pt/CMakeLists.txt
+ #  teshsuite/smpi/mpich3-test/f77/attr/CMakeLists.txt
+   teshsuite/smpi/mpich3-test/f77/coll/CMakeLists.txt
+   teshsuite/smpi/mpich3-test/f77/comm/CMakeLists.txt
+   teshsuite/smpi/mpich3-test/f77/datatype/CMakeLists.txt
+   teshsuite/smpi/mpich3-test/f77/ext/CMakeLists.txt
+   teshsuite/smpi/mpich3-test/f77/init/CMakeLists.txt
+   teshsuite/smpi/mpich3-test/f77/pt2pt/CMakeLists.txt
+   teshsuite/smpi/mpich3-test/f90/coll/CMakeLists.txt
+   teshsuite/smpi/mpich3-test/f90/datatype/CMakeLists.txt
+   teshsuite/smpi/mpich3-test/f90/init/CMakeLists.txt
+   teshsuite/smpi/mpich3-test/f90/pt2pt/CMakeLists.txt
    teshsuite/xbt/CMakeLists.txt
    )
  
@@@ -1021,6 -1021,7 +1039,7 @@@ set(PLATFORMS_EXAMPLE
    examples/platforms/conf/transform_optorsim_platform.pl
    examples/platforms/config.xml
    examples/platforms/content/storage_content.txt
+   examples/platforms/content/win_storage_content.txt
    examples/platforms/data_center.xml
    examples/platforms/g5k.xml
    examples/platforms/generation_scripts/create_hierarchical_clusters.pl
diff --combined include/msg/datatypes.h
@@@ -1,4 -1,5 +1,5 @@@
- /* Copyright (c) 2004-2012. The SimGrid Team. All rights reserved.          */
+ /* Copyright (c) 2004-2013. 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. */
@@@ -27,7 -28,7 +28,7 @@@ SG_BEGIN_DECL(
  typedef struct s_smx_rvpoint *msg_mailbox_t;
  
  /* ******************************** Environment ************************************ */
 -typedef struct s_as *msg_as_t;
 +typedef struct As *msg_as_t;
  
  /* ******************************** Host ************************************ */
  
@@@ -102,20 -103,46 +103,46 @@@ typedef struct msg_vm 
  /* ******************************** File ************************************ */
  typedef struct simdata_file *simdata_file_t;
  
+ typedef struct s_msg_file_info {
+   sg_storage_size_t size;
+   char* mount_point;
+   char* storageId;
+   char* storage_type;
+   char* content_type;
+ } s_msg_file_info_t, *msg_file_info_t;
  typedef struct msg_file {
-   char *name;                   /**< @brief file name */
-   size_t size;
-   simdata_file_t simdata;                /**< @brief simulator data  */
-   void *data;                   /**< @brief user data */
+   char *fullname;               /**< @brief file full name (path+name)*/
+   simdata_file_t simdata;       /**< @brief simulator data  */
+   msg_file_info_t info;
  } s_msg_file_t;
  
  /** @brief File datatype.
-     @ingroup msg_file_management 
-  
-     You should consider this as an opaque object.
+  *  @ingroup msg_file_management
+  *
+  *  You should consider this as an opaque object.
   */
  typedef struct msg_file *msg_file_t;
  
+ /* ******************************** Storage ************************************ */
+ /* TODO: PV: to comment */
+ extern int MSG_STORAGE_LEVEL;
+ /** @brief Storage datatype.
+  *  @ingroup msg_storage_management
+  *
+  *  You should consider this as an opaque object.
+  */
+ typedef xbt_dictelm_t msg_storage_t;
+ typedef s_xbt_dictelm_t s_msg_storage_t;
+ typedef struct msg_storage_priv  {
+   // TODO PV: fill it (or not) !
+   void * dummy;
+ } s_msg_storage_priv_t, *msg_storage_priv_t;
  /*************** Begin GPU ***************/
  typedef struct simdata_gpu_task *simdata_gpu_task_t;
  
diff --combined include/simgrid/platf.h
@@@ -1,6 -1,7 +1,7 @@@
  /* platf.h - Public interface to the SimGrid platforms                      */
  
- /* Copyright (c) 2004-2012. The SimGrid Team. All rights reserved.          */
+ /* Copyright (c) 2004-2013. 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. */
  
  #include <xbt.h>
  
 -typedef void *sg_routing_link_t; /* The actual type is model-dependent so use void* instead*/
 -typedef struct s_routing_edge *sg_routing_edge_t;
 +typedef void *sg_routing_link_t; /* FIXME:The actual type is model-dependent so use void* instead*/
 +typedef struct RoutingEdge *sg_routing_edge_t;
  
 +#ifdef __cplusplus
 +extern "C" {
 +#endif
  XBT_PUBLIC(sg_routing_edge_t) sg_routing_edge_by_name_or_null(const char *name);
 +#ifdef __cplusplus
 +}
 +#endif
  
  /** Defines whether a given resource is working or not */
  typedef enum {
@@@ -52,9 -47,6 +53,9 @@@ typedef struct tmgr_trace *tmgr_trace_t
  /** opaque structure defining a event generator for availability based on a probability distribution */
  typedef struct probabilist_event_generator *probabilist_event_generator_t;
  
 +#ifdef __cplusplus
 +extern "C" {
 +#endif
  XBT_PUBLIC(tmgr_trace_t) tmgr_trace_new_from_file(const char *filename);
  XBT_PUBLIC(tmgr_trace_t) tmgr_trace_new_from_string(const char *id,
                                                      const char *input,
@@@ -79,15 -71,18 +80,22 @@@ XBT_PUBLIC(probabilist_event_generator_
  XBT_PUBLIC(probabilist_event_generator_t) tmgr_event_generator_new_weibull(const char* id,
                                                                             double scale,
                                                                             double shape);
 +#ifdef __cplusplus
 +}
 +#endif
 +
  typedef xbt_dictelm_t sg_host_t;
  static inline char* sg_host_name(sg_host_t host) {
    return host->key;
  }
  
+ typedef xbt_dictelm_t sg_storage_t;
+ static inline char* sg_storage_name(sg_storage_t storage) {
+   return storage->key;
+ }
+ /* Type for any integer storage size  */
+ typedef uint64_t sg_storage_size_t;
  
  /*
   * Platform creation functions. Instead of passing 123 arguments to the creation functions
  
  typedef struct {
    const char* id;
-   double power_peak;
+   xbt_dynar_t power_peak;
+   int pstate;
    int core_amount;
    double power_scale;
    tmgr_trace_t power_trace;
@@@ -231,6 -227,7 +240,7 @@@ typedef struct 
    const char* id;
    const char* type_id;
    const char* content;
+   const char* content_type;
    xbt_dict_t properties;
  } s_sg_platf_storage_cbarg_t, *sg_platf_storage_cbarg_t;
  
@@@ -240,8 -237,9 +250,9 @@@ typedef struct 
    const char* id;
    const char* model;
    const char* content;
+   const char* content_type;
    xbt_dict_t properties;
-   unsigned long size; /* size in Gbytes */
+   sg_storage_size_t size;
  } s_sg_platf_storage_type_cbarg_t, *sg_platf_storage_type_cbarg_t;
  
  #define SG_PLATF_STORAGE_TYPE_INITIALIZER {NULL,NULL,NULL,NULL,NULL}
@@@ -254,7 -252,7 +265,7 @@@ typedef struct 
  #define SG_PLATF_MSTORAGE_INITIALIZER {NULL,NULL}
  
  typedef struct {
-   const char* id;
+   const char* storageId;
    const char* name;
  } s_sg_platf_mount_cbarg_t, *sg_platf_mount_cbarg_t;
  
@@@ -321,10 -319,6 +332,10 @@@ typedef struct s_sg_platf_gpu_cbarg 
  
  /* ***************************************** */
  
 +#ifdef __cplusplus
 +extern "C" {
 +#endif
 +
  XBT_PUBLIC(void) sg_platf_begin(void);  // Start a new platform
  XBT_PUBLIC(void) sg_platf_end(void); // Finish the creation of the platform
  
@@@ -374,8 -368,5 +385,8 @@@ XBT_PUBLIC(void) sg_platf_ASroute_add_l
  typedef void (*sg_platf_process_cb_t)(sg_platf_process_cbarg_t);
  XBT_PUBLIC(void) sg_platf_process_add_cb(sg_platf_process_cb_t fct);
  
 +#ifdef __cplusplus
 +}
 +#endif
  
  #endif                          /* SG_PLATF_H */
@@@ -1,4 -1,4 +1,4 @@@
- /* Copyright (c) 2004, 2005, 2006, 2007, 2008, 2009, 2010. The SimGrid Team.
+ /* Copyright (c) 2004-2013. The SimGrid Team.
   * All rights reserved.                                                     */
  
  /* This program is free software; you can redistribute it and/or modify it
  #include "xbt/lib.h"
  #include "simgrid/platf_interface.h"
  
 +#ifdef __cplusplus
 +extern "C" {
 +#endif
 +
  XBT_PUBLIC(xbt_lib_t) host_lib;
  XBT_PUBLIC(int) ROUTING_HOST_LEVEL; //Routing level
  XBT_PUBLIC(int)  SURF_CPU_LEVEL;    //Surf cpu level
  XBT_PUBLIC(int) SURF_WKS_LEVEL;    //Surf workstation level
- XBT_PUBLIC(int) SIMIX_HOST_LEVEL;  //Simix level
+ XBT_PUBLIC(int) SIMIX_HOST_LEVEL;  //Simix host level
+ XBT_PUBLIC(int) SIMIX_STORAGE_LEVEL;  //Simix storage level
  XBT_PUBLIC(int)  MSG_HOST_LEVEL;    //Msg level
- XBT_PUBLIC(int)  SD_HOST_LEVEL;    //Simdag level
+ XBT_PUBLIC(int)  SD_HOST_LEVEL;    //Simdag host level
+ XBT_PUBLIC(int)  SD_STORAGE_LEVEL;    //Simdag storage level
  XBT_PUBLIC(int)  COORD_HOST_LEVEL;  //Coordinates level
  XBT_PUBLIC(int) NS3_HOST_LEVEL;    //host node for ns3
  
@@@ -38,7 -36,7 +40,7 @@@ XBT_PUBLIC(int) ROUTING_PROP_ASR_LEVEL
  XBT_PUBLIC(xbt_lib_t) storage_lib;
  XBT_PUBLIC(int) ROUTING_STORAGE_LEVEL;        //Routing storage level
  XBT_PUBLIC(int) ROUTING_STORAGE_HOST_LEVEL;
- XBT_PUBLIC(int) SURF_STORAGE_LEVEL;
+ XBT_PUBLIC(int) SURF_STORAGE_LEVEL;  // Surf storage level
  
  XBT_PUBLIC(xbt_lib_t) storage_type_lib;
  XBT_PUBLIC(int) ROUTING_STORAGE_TYPE_LEVEL;   //Routing storage_type level
@@@ -49,8 -47,4 +51,8 @@@ void routing_AS_end(sg_platf_AS_cbarg_
  
  void routing_cluster_add_backbone(void* bb);
  
 +#ifdef __cplusplus
 +}
 +#endif
 +
  #endif                          /* _SURF_SURF_H */
diff --combined include/xbt/heap.h
@@@ -1,4 -1,4 +1,4 @@@
- /* Copyright (c) 2004, 2005, 2006, 2007, 2009, 2010. The SimGrid Team.
+ /* Copyright (c) 2004-2007, 2009-2011. The SimGrid Team.
   * All rights reserved.                                                     */
  
  /* This program is free software; you can redistribute it and/or modify it
@@@ -16,9 -16,6 +16,9 @@@
   *  @{
   */
  /* @brief heap datatype */
 +#ifdef __cplusplus
 +extern "C" {
 +#endif
  typedef struct xbt_heap *xbt_heap_t;
  
  XBT_PUBLIC(xbt_heap_t) xbt_heap_new(int init_size,
@@@ -36,8 -33,6 +36,8 @@@ XBT_PUBLIC(void) xbt_heap_set_update_ca
                                                                         *,
                                                                         int));
  XBT_PUBLIC(void *) xbt_heap_remove(xbt_heap_t H, int i);
 -
 +#ifdef __cplusplus
 +}
 +#endif
  /* @} */
  #endif                          /* _XBT_HEAP_H */
diff --combined include/xbt/module.h
@@@ -1,6 -1,6 +1,6 @@@
  /* module - modularize the code                                             */
  
- /* Copyright (c) 2004, 2005, 2006, 2007, 2009, 2010. The SimGrid Team.
+ /* Copyright (c) 2004-2007, 2009-2010, 2012. The SimGrid Team.
   * All rights reserved.                                                     */
  
  /* This program is free software; you can redistribute it and/or modify it
  
  #include <xbt/misc.h>           /* XBT_PUBLIC */
  
 +#ifdef __cplusplus
 +extern "C" {
 +#endif
  XBT_PUBLIC(void) xbt_init(int *argc, char **argv);
  XBT_PUBLIC(void) xbt_exit(void);
 +#ifdef __cplusplus
 +}
 +#endif
 +
  #endif                          /* _XBT_MODULE_H */
@@@ -1,6 -1,6 +1,6 @@@
  /* platf_interface.h - Internal interface to the SimGrid platforms          */
  
- /* Copyright (c) 2004, 2005, 2006, 2007, 2009, 2010, 2011. The SimGrid Team.
+ /* Copyright (c) 2004-2007, 2009-2012. The SimGrid Team.
   * All rights reserved.                                                     */
  
  /* This program is free software; you can redistribute it and/or modify it
@@@ -41,10 -41,6 +41,10 @@@ typedef void (*sg_platf_mstorage_cb_t)(
  /* ***************************************** */
  /* TUTORIAL: New TAG                         */
  
 +#ifdef __cplusplus
 +extern "C" {
 +#endif
 +
  typedef void (*sg_platf_gpu_cb_t)(sg_platf_gpu_cbarg_t);
  XBT_PUBLIC(void) sg_platf_gpu_add_cb(sg_platf_gpu_cb_t);
  /* ***************************************** */
@@@ -74,9 -70,6 +74,9 @@@ XBT_PUBLIC(void) sg_platf_mstorage_add_
  XBT_PUBLIC(void) sg_platf_storage_type_add_cb(sg_platf_storage_type_cb_t fct);
  XBT_PUBLIC(void) sg_platf_mount_add_cb(sg_platf_mount_cb_t fct);
  
 +#ifdef __cplusplus
 +}
 +#endif
  /** \brief Pick the right models for CPU, net and workstation, and call their model_init_preparse
   *
   * Must be called within parsing/creating the environment (after the <config>s, if any, and before <AS> or friends such as <cluster>)
@@@ -1,14 -1,17 +1,22 @@@
+ /* Copyright (c) 2012-2013. 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. */
  #include "xbt/config.h"
  
  /*******************************************/
  /*** Config Globals **************************/
  /*******************************************/
 +
 +#ifdef __cplusplus
 +extern "C" {
 +#endif
 +
  XBT_PUBLIC_DATA(xbt_cfg_t) _sg_cfg_set;
+ XBT_PUBLIC_DATA(int) _sg_cfg_init_status;
+ XBT_PUBLIC_DATA(int) _sg_cfg_exit_asap;
  XBT_PUBLIC(int) sg_cfg_get_int(const char* name);
  XBT_PUBLIC(double) sg_cfg_get_double(const char* name);
  XBT_PUBLIC(char*) sg_cfg_get_string(const char* name);
@@@ -18,7 -21,3 +26,7 @@@ XBT_PUBLIC(xbt_dynar_t) sg_cfg_get_dyna
  
  void sg_config_init(int *argc, char **argv);
  void sg_config_finalize(void);
 +
 +#ifdef __cplusplus
 +}
 +#endif
@@@ -1,4 -1,4 +1,4 @@@
- /* Copyright (c) 2009, 2010. The SimGrid Team.
+ /* Copyright (c) 2009-2013. The SimGrid Team.
   * All rights reserved.                                                     */
  
  /* This program is free software; you can redistribute it and/or modify it
@@@ -13,7 -13,7 +13,7 @@@
   *  Generic data structure for a model. The workstations,
   *  the CPUs and the network links are examples of models.
   */
 -typedef struct surf_model *surf_model_t;
 +//FIXME: typedef struct surf_model *surf_model_t;
  
  /** \ingroup SURF_actions
   *  \brief Action datatype
@@@ -21,8 -21,9 +21,9 @@@
   * An action is some working amount on a model.
   * It is represented as a cost, a priority, a duration and a state.
   */
 -typedef struct surf_action *surf_action_t;
 -typedef struct surf_file *surf_file_t;
 +//FIXME:typedef struct surf_action *surf_action_t;
 +//FIXME:typedef struct surf_file *surf_file_t;
+ typedef struct surf_storage *surf_storage_t;
  typedef struct surf_stat *surf_stat_t;
  
  typedef struct lmm_element *lmm_element_t;
@@@ -1,4 -1,4 +1,4 @@@
- /* Copyright (c) 2004, 2005, 2006, 2007, 2008, 2009, 2010. The SimGrid Team.
+ /* Copyright (c) 2004-2013. The SimGrid Team.
   * All rights reserved.                                                     */
  
  /* This program is free software; you can redistribute it and/or modify it
@@@ -31,10 -31,6 +31,10 @@@ static XBT_INLINE int double_equals(dou
    return (fabs(value1 - value2) < MAXMIN_PRECISION);
  }
  
 +#ifdef __cplusplus
 +extern "C" {
 +#endif
 +
  XBT_PUBLIC(lmm_system_t) lmm_system_new(int selective_update);
  XBT_PUBLIC(void) lmm_system_free(lmm_system_t sys);
  void lmm_variable_disable(lmm_system_t sys, lmm_variable_t var);
@@@ -46,6 -42,8 +46,8 @@@ int lmm_constraint_is_shared(lmm_constr
  
  void lmm_constraint_free(lmm_system_t sys, lmm_constraint_t cnst);
  
+ double lmm_constraint_get_usage(lmm_constraint_t cnst);
  XBT_PUBLIC(lmm_variable_t) lmm_variable_new(lmm_system_t sys, void *id,
                                              double weight_value,
                                              double bound,
@@@ -130,8 -128,5 +132,8 @@@ XBT_PUBLIC(double func_vegas_f) (lmm_va
  XBT_PUBLIC(double func_vegas_fp) (lmm_variable_t var, double x);
  XBT_PUBLIC(double func_vegas_fpi) (lmm_variable_t var, double x);
  
 +#ifdef __cplusplus
 +}
 +#endif
  
  #endif                          /* _SURF_MAXMIN_H */
diff --combined src/include/surf/surf.h
@@@ -1,4 -1,4 +1,4 @@@
- /* Copyright (c) 2004, 2005, 2006, 2007, 2008, 2009, 2010. The SimGrid Team.
+ /* Copyright (c) 2004-2013. The SimGrid Team.
   * All rights reserved.                                                     */
  
  /* This program is free software; you can redistribute it and/or modify it
@@@ -35,6 -35,7 +35,6 @@@ extern int sg_gtnets_jitter_seed
  #endif
  extern xbt_dynar_t surf_path;
  
 -
  typedef enum {
    SURF_NETWORK_ELEMENT_NULL = 0,        /* NULL */
    SURF_NETWORK_ELEMENT_HOST,    /* host type */
    SURF_NETWORK_ELEMENT_AS       /* AS type */
  } e_surf_network_element_type_t;
  
 +#ifdef __cplusplus
 +class Model;
 +class CpuModel;
 +class WorkstationModel;
 +class NetworkCm02Model;
++class StorageModel;
 +class Resource;
 +class ResourceLmm;
 +class WorkstationCLM03;
 +class NetworkCm02Link;
 +class Cpu;
 +class Action;
 +class ActionLmm;
 +class StorageActionLmm;
 +class As;
 +class RoutingEdge;
 +class RoutingPlatf;
 +#else
 +typedef struct Model Model;
 +typedef struct CpuModel CpuModel;
 +typedef struct WorkstationModel WorkstationModel;
 +typedef struct NetworkCm02Model NetworkCm02Model;
++typedef struct StorageModel StorageModel;
 +typedef struct Resource Resource;
 +typedef struct ResourceLmm ResourceLmm;
 +typedef struct WorkstationCLM03 WorkstationCLM03;
 +typedef struct NetworkCm02Link NetworkCm02Link;
 +typedef struct Cpu Cpu;
 +typedef struct Action Action;
 +typedef struct ActionLmm ActionLmm;
 +typedef struct StorageActionLmm StorageActionLmm;
 +typedef struct As As;
 +typedef struct RoutingEdge RoutingEdge;
 +typedef struct RoutingPlatf RoutingPlatf;
 +#endif
 +
 +/** \ingroup SURF_models
 + *  \brief Model datatype
 + *
 + *  Generic data structure for a model. The workstations,
 + *  the CPUs and the network links are examples of models.
 + */
 +typedef Model *surf_model_t;
 +typedef CpuModel *surf_cpu_model_t;
 +typedef WorkstationModel *surf_workstation_model_t;
 +typedef NetworkCm02Model *surf_network_model_t;
++typedef StorageModel *surf_storage_model_t;
 +
 +typedef xbt_dictelm_t surf_resource_t;
 +typedef Resource *surf_cpp_resource_t;
 +typedef WorkstationCLM03 *surf_workstation_CLM03_t;
 +typedef NetworkCm02Link *surf_network_link_t;
 +typedef Cpu *surf_cpu_t;
 +
 +/** \ingroup SURF_actions
 + *  \brief Action structure
 + *
 + *  Never create s_surf_action_t by yourself ! The actions are created
 + *  on the fly when you call execute or communicate on a model.
 + *
 + *  \see e_surf_action_state_t
 + */
 +typedef Action *surf_action_t;
 +typedef ActionLmm *surf_action_lmm_t;
 +typedef StorageActionLmm *surf_storage_action_lmm_t;
 +
 +typedef As *AS_t;
 +typedef RoutingEdge *routing_edge_t;
 +typedef RoutingPlatf *routing_platf_t;
 +
 +typedef struct surf_file *surf_file_t;
 +
  XBT_PUBLIC(e_surf_network_element_type_t)
    routing_get_network_element_type(const char* name);
  
@@@ -140,7 -72,57 +143,7 @@@ XBT_PUBLIC(int) find_model_description(
  XBT_PUBLIC(void) model_help(const char *category,
                              s_surf_model_description_t * table);
  
 -enum heap_action_type{
 -  LATENCY = 100,
 -  MAX_DURATION,
 -  NORMAL,
 -  NOTSET
 -};
 -
 -/** \ingroup SURF_actions
 - *  \brief Action structure
 - *
 - *  Never create s_surf_action_t by yourself ! The actions are created
 - *  on the fly when you call execute or communicate on a model.
 - *
 - *  \see e_surf_action_state_t
 - */
 -typedef struct surf_action {
 -  s_xbt_swag_hookup_t state_hookup;
 -  xbt_swag_t state_set;
 -  double cost;                  /**< cost        */
 -  double priority;              /**< priority (1.0 by default) */
 -  double max_duration;          /**< max_duration (may fluctuate until
 -           the task is completed) */
 -  double remains;               /**< How much of that cost remains to
 -         * be done in the currently running task */
 -#ifdef HAVE_LATENCY_BOUND_TRACKING
 -  int latency_limited;               /**< Set to 1 if is limited by latency, 0 otherwise */
 -#endif
  
 -  double start;                 /**< start time  */
 -  double finish;                /**< finish time : this is modified during the run
 -         * and fluctuates until the task is completed */
 -  void *data;                   /**< for your convenience */
 -  int refcount;
 -  surf_model_t model_type;
 -#ifdef HAVE_TRACING
 -  char *category;               /**< tracing category for categorized resource utilization monitoring */
 -#endif
 -  surf_file_t file;        /**< surf_file_t for storage model */
 -  xbt_dict_t ls_dict;
 -} s_surf_action_t;
 -
 -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;
 -  double last_value;
 -  enum heap_action_type hat;
 -} s_surf_action_lmm_t, *surf_action_lmm_t;
  
  /** \ingroup SURF_actions
   *  \brief Action states
   *
   *  \see surf_action_t, surf_action_state_t
   */
 +
  typedef enum {
    SURF_ACTION_READY = 0,        /**< Ready        */
    SURF_ACTION_RUNNING,          /**< Running      */
                                  /**< Not in the system anymore. Why did you ask ? */
  } e_surf_action_state_t;
  
 -/** \ingroup SURF_actions
 - *  \brief Action state sets
 - *
 - *  This structure contains some sets of actions.
 - *  It provides a fast access to the actions in each state.
 - *
 - *  \see surf_action_t, e_surf_action_state_t
 - */
 -typedef struct surf_action_state {
 -  xbt_swag_t ready_action_set;
 -                                 /**< Actions in state SURF_ACTION_READY */
 -  xbt_swag_t running_action_set;
 -                                 /**< Actions in state SURF_ACTION_RUNNING */
 -  xbt_swag_t failed_action_set;
 -                                 /**< Actions in state SURF_ACTION_FAILED */
 -  xbt_swag_t done_action_set;
 -                                 /**< Actions in state SURF_ACTION_DONE */
 -} s_surf_action_state_t, *surf_action_state_t;
 -
  /***************************/
  /* Generic model object */
  /***************************/
 -typedef struct s_routing_platf s_routing_platf_t, *routing_platf_t;
 +//FIXME:REMOVE typedef struct s_routing_platf s_routing_platf_t, *routing_platf_t;
  XBT_PUBLIC_DATA(routing_platf_t) routing_platf;
  
  /*******************************************
@@@ -196,6 -196,11 +199,11 @@@ typedef struct surf_cpu_model_extension
    int (*get_core) (void *cpu);
    double (*get_speed) (void *cpu, double load);
    double (*get_available_speed) (void *cpu);
+   double (*get_current_power_peak) (void *cpu);
+   double (*get_power_peak_at) (void *cpu, int pstate_index);
+   int (*get_nb_pstates) (void *cpu);
+   void (*set_power_peak_at) (void *cpu, int pstate_index);
+   double (*get_consumed_energy) (void *cpu);
    void (*add_traces) (void);
  } s_surf_model_extension_cpu_t;
  
@@@ -218,7 -223,7 +226,7 @@@ typedef struct surf_network_model_exten
  } s_surf_model_extension_network_t;
  
  /* Storage model */
- //
  /** \ingroup SURF_models
   *  \brief Storage model extension public
   *
  typedef struct surf_storage_model_extension_public {
    surf_action_t(*open) (void *storage, const char* mount, const char* path);
    surf_action_t(*close) (void *storage, surf_file_t fd);
-   surf_action_t(*read) (void *storage, void* ptr, size_t size,
-                         surf_file_t fd);
-   surf_action_t(*write) (void *storage, const void* ptr, size_t size,
-                          surf_file_t fd);
+   surf_action_t(*read) (void *storage, surf_file_t fd, sg_storage_size_t size);
+   surf_action_t(*write) (void *storage, surf_file_t fd, sg_storage_size_t size);
    surf_action_t(*stat) (void *storage, surf_file_t fd);
    surf_action_t(*ls) (void *storage, const char *path);
+   xbt_dict_t(*get_properties) (const void *storage);
+   xbt_dict_t(*get_content) (void *storage);
+   sg_storage_size_t(*get_size) (void *storage);
  } s_surf_model_extension_storage_t;
  
       /** \ingroup SURF_models
@@@ -246,9 -252,18 +255,18 @@@ typedef struct surf_workstation_model_e
                                        and create the corresponding action */
    surf_action_t(*sleep) (void *workstation, double duration);                              /**< Make a workstation sleep during a given duration */
    e_surf_resource_state_t(*get_state) (void *workstation);                                      /**< Return the CPU state of a workstation */
    int (*get_core) (void *workstation); 
    double (*get_speed) (void *workstation, double load);                                    /**< Return the speed of a workstation */
    double (*get_available_speed) (void *workstation);                                       /**< Return tha available speed of a workstation */
+   double (*get_current_power_peak) (void *workstation);                                         /**< Return the current CPU speed of a workstation */
+   double (*get_power_peak_at) (void *workstation, int pstate_index);                    /**< Return the speed of a workstation for a specific pstate,
+                                                                                                (where higher pstate values represent lower processor speeds) */
+   int (*get_nb_pstates) (void *workstation);                                            /**< Return the number of pstates defined for a workstation (default is 1) */
+   void (*set_power_peak_at) (void *workstation, int pstate_index);                      /**< Set the processor speed of a workstation to the speed associated with the pstate_index pstate */
+   double (*get_consumed_energy) (void *workstation);                                    /**< Return the total energy consumed by a workstation */
     surf_action_t(*communicate) (void *workstation_src,                                     /**< Execute a communication amount between two workstations */
                                  void *workstation_dst, double size,
                                  double max_rate);
    surf_action_t(*open) (void *workstation, const char* storage,
                          const char* path);
    surf_action_t(*close) (void *workstation, surf_file_t fd);
-   surf_action_t(*read) (void *workstation, void* ptr, size_t size,
-                         surf_file_t fd);
-   surf_action_t(*write) (void *workstation, const void* ptr, size_t size,
-                          surf_file_t fd);
+   surf_action_t(*read) (void *workstation, surf_file_t fd, sg_storage_size_t size);
+   surf_action_t(*write) (void *workstation, surf_file_t fd, sg_storage_size_t size);
    surf_action_t(*stat) (void *workstation, surf_file_t fd);
    int(*unlink) (void *workstation, surf_file_t fd);
    surf_action_t(*ls) (void *workstation, const char* mount, const char *path);
-   size_t (*get_size) (void *workstation, surf_file_t fd);
+   sg_storage_size_t (*get_size) (void *workstation, surf_file_t fd);
+   xbt_dynar_t (*get_info) (void *workstation, surf_file_t fd);
  
    int (*link_shared) (const void *link);
-    xbt_dict_t(*get_properties) (const void *resource);
+   xbt_dict_t(*get_properties) (const void *resource);
    void (*add_traces) (void);
  
+   sg_storage_size_t (*get_free_size) (void *workstation,const char* name);
+   sg_storage_size_t (*get_used_size) (void *workstation,const char* name);
+   xbt_dict_t (*get_storage_list) (void *workstation);
  } s_surf_model_extension_workstation_t;
  
  
 -
 -
 -/** \ingroup SURF_models
 - *  \brief Model datatype
 - *
 - *  Generic data structure for a model. The workstations,
 - *  the CPUs and the network links are examples of models.
 - */
 -typedef struct surf_model {
 -  const char *name;     /**< Name of this model */
 -  s_surf_action_state_t states;      /**< Any living action on this model */
 -
 -   e_surf_action_state_t(*action_state_get) (surf_action_t action);
 -                                                                       /**< Return the state of an action */
 -  void (*action_state_set) (surf_action_t action,
 -                            e_surf_action_state_t state);
 -                                                                  /**< Change an action state*/
 -
 -  double (*action_get_start_time) (surf_action_t action);     /**< Return the start time of an action */
 -  double (*action_get_finish_time) (surf_action_t action);     /**< Return the finish time of an action */
 -  int (*action_unref) (surf_action_t action);     /**< Specify that we don't use that action anymore. Returns true if the action was destroyed and false if someone still has references on it. */
 -  void (*action_cancel) (surf_action_t action);     /**< Cancel a running action */
 -  void (*action_recycle) (surf_action_t action);     /**< Recycle an action */
 -  void (*action_data_set) (surf_action_t action, void *data);     /**< Set the user data of an action */
 -  void (*suspend) (surf_action_t action);     /**< Suspend an action */
 -  void (*resume) (surf_action_t action);     /**< Resume a suspended action */
 -  int (*is_suspended) (surf_action_t action);     /**< Return whether an action is suspended */
 -  void (*set_max_duration) (surf_action_t action, double duration);     /**< Set the max duration of an action*/
 -  void (*set_priority) (surf_action_t action, double priority);     /**< Set the priority of an action */
 -#ifdef HAVE_TRACING
 -  void (*set_category) (surf_action_t action, const char *category); /**< Set the category of an action */
 -#endif
 -  double (*get_remains) (surf_action_t action);     /**< Get the remains of an action */
 -#ifdef HAVE_LATENCY_BOUND_TRACKING
 -  int (*get_latency_limited) (surf_action_t action);     /**< Return 1 if action is limited by latency, 0 otherwise */
 -#endif
 -
 -  void (*gap_remove) (surf_action_lmm_t action);
 -
 -  surf_model_private_t model_private;
 -
 -  union extension {
 -    s_surf_model_extension_cpu_t cpu;
 -    s_surf_model_extension_network_t network;
 -    s_surf_model_extension_storage_t storage;
 -    s_surf_model_extension_workstation_t workstation;
 -    /*******************************************/
 -    /* TUTORIAL: New model                     */
 -    s_surf_model_extension_new_model_t new_model;
 -    /*******************************************/
 -  } extension;
 -} s_surf_model_t;
 -
 -surf_model_t surf_model_init(void);
 -void surf_model_exit(surf_model_t model);
 -
  static inline void *surf_cpu_resource_priv(const void *host) {
 -  return xbt_lib_get_level((void *)host, SURF_CPU_LEVEL);
 +  return xbt_lib_get_level((xbt_dictelm_t)host, SURF_CPU_LEVEL);
  }
  static inline void *surf_workstation_resource_priv(const void *host){
 -  return xbt_lib_get_level((void *)host, SURF_WKS_LEVEL);
 +  return (void*)xbt_lib_get_level((xbt_dictelm_t)host, SURF_WKS_LEVEL);
  }
- static inline void *surf_storage_resource_priv(const void *host){
-   return (void*)xbt_lib_get_level((xbt_dictelm_t)host, SURF_STORAGE_LEVEL);
+ static inline void *surf_storage_resource_priv(const void *storage){
 -  return xbt_lib_get_level((void *)storage, SURF_STORAGE_LEVEL);
++  return (void*)xbt_lib_get_level((xbt_dictelm_t)storage, SURF_STORAGE_LEVEL);
  }
  
  static inline void *surf_cpu_resource_by_name(const char *name) {
@@@ -301,65 -375,29 +322,76 @@@ static inline void *surf_storage_resour
    return xbt_lib_get_elm_or_null(storage_lib, name);
  }
  
 -typedef struct surf_resource {
 -  surf_model_t model;
 -  char *name;
 -  xbt_dict_t properties;
 -  void_f_pvoid_t free_f;
 -} s_surf_resource_t, *surf_resource_t;
 -
 -/**
 - * Resource which have a metric handled by a maxmin system
 - */
 -typedef struct {
 -  double scale;
 -  double peak;
 -  tmgr_trace_event_t event;
 -} s_surf_metric_t;
 -
 -typedef struct surf_resource_lmm {
 -  s_surf_resource_t generic_resource;
 -  lmm_constraint_t constraint;
 -  e_surf_resource_state_t state_current;
 -  tmgr_trace_event_t state_event;
 -  s_surf_metric_t power;
 -} s_surf_resource_lmm_t, *surf_resource_lmm_t;
 +#ifdef __cplusplus
 +extern "C" {
 +#endif
 +char *surf_routing_edge_name(sg_routing_edge_t edge);
 +void *surf_as_cluster_get_backbone(AS_t as);
 +void surf_as_cluster_set_backbone(AS_t as, void* backbone);
 +const char *surf_model_name(surf_model_t model);
 +xbt_swag_t surf_model_done_action_set(surf_model_t model);
 +xbt_swag_t surf_model_failed_action_set(surf_model_t model);
 +xbt_swag_t surf_model_ready_action_set(surf_model_t model);
 +xbt_swag_t surf_model_running_action_set(surf_model_t model);
 +surf_action_t surf_workstation_model_execute_parallel_task(surf_workstation_model_t model,
 +                                                  int workstation_nb,
 +                                            void **workstation_list,
 +                                            double *computation_amount,
 +                                            double *communication_amount,
 +                                            double rate);
 +surf_action_t surf_workstation_model_communicate(surf_workstation_model_t model, surf_resource_t src, surf_resource_t dst, double size, double rate);
 +xbt_dynar_t surf_workstation_model_get_route(surf_workstation_model_t model, surf_resource_t src, surf_resource_t dst);
 +surf_action_t surf_network_model_communicate(surf_network_model_t model, sg_routing_edge_t src, sg_routing_edge_t dst, double size, double rate);
 +const char *surf_resource_name(surf_cpp_resource_t resource);
 +xbt_dict_t surf_resource_get_properties(surf_cpp_resource_t resource);
 +e_surf_resource_state_t surf_resource_get_state(surf_cpp_resource_t resource);
 +double surf_workstation_get_speed(surf_resource_t resource, double load);
 +double surf_workstation_get_available_speed(surf_resource_t resource);
 +int surf_workstation_get_core(surf_resource_t resource);
 +surf_action_t surf_workstation_execute(surf_resource_t resource, double size);
 +surf_action_t surf_workstation_sleep(surf_resource_t resource, double duration);
 +surf_action_t surf_workstation_open(surf_resource_t workstation, const char* mount, const char* path);
 +surf_action_t surf_workstation_close(surf_resource_t workstation, surf_file_t fd);
++surf_action_t surf_workstation_read(surf_resource_t resource, surf_file_t fd, sg_storage_size_t size);
++surf_action_t surf_workstation_write(surf_resource_t resource, surf_file_t fd, sg_storage_size_t size);
++xbt_dynar_t surf_workstation_get_info(surf_resource_t resource, surf_file_t fd);
++sg_storage_size_t surf_workstation_get_free_size(surf_resource_t resource, const char* name);
++sg_storage_size_t surf_workstation_get_used_size(surf_resource_t resource, const char* name);
 +surf_action_t surf_cpu_execute(surf_resource_t cpu, double size);
 +surf_action_t surf_cpu_sleep(surf_resource_t cpu, double duration);
++double surf_workstation_get_current_power_peak(surf_resource_t host);
++double surf_workstation_get_power_peak_at(surf_resource_t host, int pstate_index);
++int surf_workstation_get_nb_pstates(surf_resource_t host);
++void surf_workstation_set_power_peak_at(surf_resource_t host, int pstate_index);
++double surf_workstation_get_consumed_energy(surf_resource_t host);
++xbt_dict_t surf_workstation_get_storage_list(surf_resource_t workstation);
 +int surf_workstation_unlink(surf_resource_t workstation, surf_file_t fd);
 +surf_action_t surf_workstation_ls(surf_resource_t workstation, const char* mount, const char *path);
 +size_t surf_workstation_get_size(surf_resource_t workstation, surf_file_t fd);
- surf_action_t surf_workstation_read(surf_resource_t resource, void *ptr, size_t size, surf_file_t fd);
- surf_action_t surf_workstation_write(surf_resource_t resource, const void *ptr, size_t size, surf_file_t fd);
 +int surf_network_link_is_shared(surf_cpp_resource_t link);
 +double surf_network_link_get_bandwidth(surf_cpp_resource_t link);
 +double surf_network_link_get_latency(surf_cpp_resource_t link);
++xbt_dict_t surf_storage_get_content(surf_resource_t resource);
++sg_storage_size_t surf_storage_get_size(surf_resource_t resource);
 +void *surf_action_get_data(surf_action_t action);
 +void surf_action_set_data(surf_action_t action, void *data);
 +void surf_action_unref(surf_action_t action);
 +double surf_action_get_start_time(surf_action_t action);
 +double surf_action_get_finish_time(surf_action_t action);
 +double surf_action_get_remains(surf_action_t action);
 +void surf_action_suspend(surf_action_t action);
 +void surf_action_resume(surf_action_t action);
 +void surf_action_cancel(surf_action_t action);
 +void surf_action_set_priority(surf_action_t action, double priority);
 +void surf_action_set_category(surf_action_t action, const char *category);
 +e_surf_action_state_t surf_action_get_state(surf_action_t action);
 +int surf_action_get_cost(surf_action_t action);
 +surf_file_t surf_storage_action_get_file(surf_action_t action);
 +xbt_dict_t surf_storage_action_get_ls_dict(surf_action_t action);
 +
 +#ifdef __cplusplus
 +}
 +#endif
  
  /**************************************/
  /* Implementations of model object */
  /** \ingroup SURF_models
   *  \brief The CPU model
   */
 -XBT_PUBLIC_DATA(surf_model_t) surf_cpu_model;
 +XBT_PUBLIC_DATA(surf_cpu_model_t) surf_cpu_model;
  
  /** \ingroup SURF_models
   *  \brief Initializes the CPU model with the model Cas01
@@@ -414,7 -452,7 +446,7 @@@ XBT_PUBLIC_DATA(s_surf_model_descriptio
   *  model should be accessed because depending on the platform model,
   *  the network model can be NULL.
   */
 -XBT_PUBLIC_DATA(surf_model_t) surf_network_model;
 +XBT_PUBLIC_DATA(surf_network_model_t) surf_network_model;
  
  /** \ingroup SURF_models
   *  \brief Same as network model 'LagrangeVelho', only with different correction factors.
@@@ -550,6 -588,8 +582,8 @@@ XBT_PUBLIC(void) surf_storage_model_ini
   */
  XBT_PUBLIC_DATA(s_surf_model_description_t) surf_storage_model_description[];
  
 -XBT_PUBLIC_DATA(surf_model_t) surf_storage_model;
++XBT_PUBLIC_DATA(surf_storage_model_t) surf_storage_model;
  /** \ingroup SURF_models
   *  \brief The workstation model
   *
   *  because depending on the platform model, the network model and the CPU model
   *  may not exist.
   */
 -XBT_PUBLIC_DATA(surf_model_t) surf_workstation_model;
 +XBT_PUBLIC_DATA(surf_workstation_model_t) surf_workstation_model;
  
  /** \ingroup SURF_models
   *  \brief Initializes the platform with a compound workstation model
@@@ -597,6 -637,11 +631,6 @@@ XBT_PUBLIC(void) surf_workstation_model
  XBT_PUBLIC_DATA(s_surf_model_description_t)
      surf_workstation_model_description[];
  
 -/*******************************************
 - *  TUTORIAL: New model
 - */
 -XBT_PUBLIC(void) surf_new_model_init_default(void);
 -XBT_PUBLIC_DATA(s_surf_model_description_t) surf_new_model_description[];
  /*******************************************/
  
  /** \ingroup SURF_models
   */
  XBT_PUBLIC_DATA(xbt_dynar_t) model_list;
  
+ /** \ingroup SURF_simulation
+  *  \brief List of hosts that have juste restarted and whose autorestart process should be restarted.
+  */
+ XBT_PUBLIC_DATA(xbt_dynar_t) host_that_restart;
+ /** \ingroup SURF_simulation
+  *  \brief List of hosts for which one want to be notified if they ever restart.
+  */
+ XBT_PUBLIC(xbt_dict_t) watched_hosts_lib;
  /*******************************************/
  /*** SURF Platform *************************/
  /*******************************************/
 -typedef struct s_as *AS_t;
 -
 +#ifdef __cplusplus
 +extern "C" {
 +#endif
  XBT_PUBLIC_DATA(AS_t) surf_AS_get_routing_root(void); 
  XBT_PUBLIC_DATA(const char *) surf_AS_get_name(AS_t as);
  XBT_PUBLIC_DATA(xbt_dict_t) surf_AS_get_routing_sons(AS_t as);
  XBT_PUBLIC_DATA(const char *) surf_AS_get_model(AS_t as);
  XBT_PUBLIC_DATA(xbt_dynar_t) surf_AS_get_hosts(AS_t as);
 +XBT_PUBLIC_DATA(void) surf_AS_get_graph(AS_t as, xbt_graph_t graph, xbt_dict_t nodes, xbt_dict_t edges);
 +XBT_PUBLIC_DATA(AS_t) surf_platf_get_root(routing_platf_t platf);
 +XBT_PUBLIC_DATA(e_surf_network_element_type_t) surf_routing_edge_get_rc_type(sg_routing_edge_t edge);
 +#ifdef __cplusplus
 +}
 +#endif
  
  /*******************************************/
  /*** SURF Globals **************************/
@@@ -665,7 -713,6 +709,6 @@@ XBT_PUBLIC(double) surf_solve(double ma
   *
   *  Return the current time in millisecond.
   */
  XBT_PUBLIC(double) surf_get_clock(void);
  
  /** \ingroup SURF_simulation
@@@ -699,8 -746,6 +742,6 @@@ XBT_PUBLIC(xbt_dict_t) get_as_router_pr
  int surf_get_nthreads(void);
  void surf_set_nthreads(int nthreads);
  
- void surf_watched_hosts(void);
  /*
   * Returns the initial path. On Windows the initial path is
   * the current directory for the current process in the other
@@@ -720,7 -765,7 +761,7 @@@ void instr_routing_define_callbacks (vo
  void instr_new_variable_type (const char *new_typename, const char *color);
  void instr_new_user_variable_type  (const char *father_type, const char *new_typename, const char *color);
  void instr_new_user_state_type (const char *father_type, const char *new_typename);
 -void instr_new_value_for_user_state_type (const char *typename, const char *value, const char *color);
 +void instr_new_value_for_user_state_type (const char *_typename, const char *value, const char *color);
  int instr_platform_traced (void);
  xbt_graph_t instr_routing_platform_graph (void);
  void instr_routing_platform_graph_export_graphviz (xbt_graph_t g, const char *filename);
@@@ -1,5 -1,5 +1,5 @@@
  
- /* Copyright (c) 2009, 2010. The SimGrid Team.
+ /* Copyright (c) 2009-2013. The SimGrid Team.
   * All rights reserved.                                                     */
  
  /* This program is free software; you can redistribute it and/or modify it
@@@ -9,21 -9,24 +9,24 @@@
  #ifndef SURF_RESOURCE_H
  #define SURF_RESOURCE_H
  
 -static XBT_INLINE
 +/*FIXME:DELETEstatic XBT_INLINE
      surf_resource_t surf_resource_new(size_t childsize,
                                        surf_model_t model, const char *name,
-                                       xbt_dict_t props)
+                                       xbt_dict_t props, void_f_pvoid_t free_f)
  {
    surf_resource_t res = xbt_malloc0(childsize);
    res->model = model;
    res->name = xbt_strdup(name);
    res->properties = props;
+   res->free_f=free_f;
    return res;
  }
  
  static XBT_INLINE void surf_resource_free(void *r)
  {
    surf_resource_t resource = r;
+   if(resource->free_f)
+     resource->free_f(r);
    free(resource->name);
    xbt_dict_free(&resource->properties);
    free(resource);
@@@ -37,6 -40,6 +40,6 @@@ static XBT_INLINE const char *surf_reso
  static XBT_INLINE xbt_dict_t surf_resource_properties(const void *resource)
  {
    return ((surf_resource_t) resource)->properties;
 -}
 +}*/
  
  #endif                          /* SURF_RESOURCE_H */
@@@ -1,5 -1,5 +1,5 @@@
  
- /* Copyright (c) 2009, 2010. The SimGrid Team.
+ /* Copyright (c) 2009-2013. The SimGrid Team.
   * All rights reserved.                                                     */
  
  /* This program is free software; you can redistribute it and/or modify it
@@@ -11,7 -11,7 +11,7 @@@
  #include "surf/trace_mgr.h"
  #include "surf/surf_resource.h"
  
 -
 +#ifdef TOMATO
  static XBT_INLINE
      surf_resource_lmm_t surf_resource_lmm_new(size_t childsize,
                                                /* for superclass */
@@@ -28,7 -28,7 +28,7 @@@
  
    surf_resource_lmm_t res =
        (surf_resource_lmm_t) surf_resource_new(childsize, model, name,
-                                               props);
+                                               props, NULL);
  
    res->constraint = lmm_constraint_new(system, res, constraint_value);
    res->state_current = state_init;
@@@ -43,7 -43,7 +43,7 @@@
          tmgr_history_add_trace(history, metric_trace, 0.0, 0, res);
    return res;
  }
 -
 +#endif
  
  static XBT_INLINE e_surf_resource_state_t surf_resource_lmm_get_state(void
                                                                        *r)
@@@ -1,4 -1,4 +1,4 @@@
- /* Copyright (c) 2004, 2005, 2006, 2007, 2009, 2010. The SimGrid Team.
+ /* Copyright (c) 2004-2007, 2009-2012. The SimGrid Team.
   * All rights reserved.                                                     */
  
  /* This program is free software; you can redistribute it and/or modify it
  #include "surf/datatypes.h"
  #include "simgrid/platf_interface.h"
  
 +#ifdef __cplusplus
 +extern "C" {
 +#endif
 +
  /* Creation functions */
  XBT_PUBLIC(tmgr_history_t) tmgr_history_new(void);
  XBT_PUBLIC(void) tmgr_history_free(tmgr_history_t history);
@@@ -47,8 -43,4 +47,8 @@@ XBT_PUBLIC(tmgr_trace_event_t
  
  XBT_PUBLIC(void) tmgr_finalize(void);
  
 +#ifdef __cplusplus
 +}
 +#endif
 +
  #endif                          /* _SURF_TMGR_H */
@@@ -1,4 -1,4 +1,4 @@@
- /* Copyright (c) 2010. The SimGrid Team.
+ /* Copyright (c) 2010-2013. The SimGrid Team.
   * All rights reserved.                                                     */
  
  /* This program is free software; you can redistribute it and/or modify it
@@@ -8,10 -8,7 +8,10 @@@
  
  #ifdef HAVE_TRACING
  #include "instr/instr_private.h"
 -#include "surf/network_private.h"
 +#include "surf/surf.h"
 +#include "surf/surf_private.h"
 +
 +//FIXME:#include "surf/network_private.h"
  
  typedef enum {
    INSTR_US_DECLARE,
@@@ -377,7 -374,7 +377,7 @@@ static void instr_user_srcdst_variable(
    unsigned int i;
    void *link;
    xbt_dynar_foreach (route, i, link) {
 -    char *link_name = ((link_CM02_t)link)->lmm_resource.generic_resource.name;
 +    char *link_name = (char*)surf_resource_name(link);
      instr_user_variable (time, link_name, variable, father_type, value, what, NULL, user_link_variables);
    }
  }
@@@ -1,4 -1,4 +1,4 @@@
- /* Copyright (c) 2010. The SimGrid Team.
+ /* Copyright (c) 2010-2013. The SimGrid Team.
   * All rights reserved.                                                     */
  
  /* This program is free software; you can redistribute it and/or modify it
@@@ -102,12 -102,8 +102,12 @@@ extern xbt_dict_t user_vm_variables
  extern xbt_dict_t user_link_variables;
  extern double TRACE_last_timestamp_to_dump;
  
 +#ifdef __cplusplus
 +extern "C" {
 +#endif
 +
  /* instr_paje_header.c */
- void TRACE_header(int basic);
+ void TRACE_header(int basic, int size);
  
  /* from paje.c */
  void TRACE_paje_start(void);
@@@ -126,9 -122,11 +126,11 @@@ XBT_PUBLIC(void) new_pajeAddVariable (d
  XBT_PUBLIC(void) new_pajeSubVariable (double timestamp, container_t container, type_t type, double value);
  XBT_PUBLIC(void) new_pajeSetState (double timestamp, container_t container, type_t type, val_t value);
  XBT_PUBLIC(void) new_pajePushState (double timestamp, container_t container, type_t type, val_t value);
+ XBT_PUBLIC(void) new_pajePushStateWithSize (double timestamp, container_t container, type_t type, val_t value, int size);
  XBT_PUBLIC(void) new_pajePopState (double timestamp, container_t container, type_t type);
  XBT_PUBLIC(void) new_pajeResetState (double timestamp, container_t container, type_t type);
  XBT_PUBLIC(void) new_pajeStartLink (double timestamp, container_t container, type_t type, container_t sourceContainer, const char *value, const char *key);
+ XBT_PUBLIC(void) new_pajeStartLinkWithSize (double timestamp, container_t container, type_t type, container_t sourceContainer, const char *value, const char *key, int size);
  XBT_PUBLIC(void) new_pajeEndLink (double timestamp, container_t container, type_t type, container_t destContainer, const char *value, const char *key);
  XBT_PUBLIC(void) new_pajeNewEvent (double timestamp, container_t container, type_t type, val_t value);
  
@@@ -151,6 -149,7 +153,7 @@@ int TRACE_disable_power(void)
  int TRACE_onelink_only (void);
  int TRACE_disable_destroy (void);
  int TRACE_basic (void);
+ int TRACE_display_sizes (void);
  char *TRACE_get_comment (void);
  char *TRACE_get_comment_file (void);
  char *TRACE_get_filename(void);
@@@ -215,10 -214,6 +218,10 @@@ XBT_PUBLIC(val_t)  PJ_value_get_or_new 
  XBT_PUBLIC(val_t)  PJ_value_get (const char *name, const type_t father);
  void PJ_value_free (val_t value);
  
 +#ifdef __cplusplus
 +}
 +#endif
 +
  #endif /* HAVE_TRACING */
  
  #ifdef HAVE_JEDULE
diff --combined src/simdag/sd_global.c
@@@ -1,4 -1,4 +1,4 @@@
- /* Copyright (c) 2006, 2007, 2008, 2009, 2010. The SimGrid Team.
+ /* Copyright (c) 2006-2013. The SimGrid Team.
   * All rights reserved.                                                     */
  
  /* This program is free software; you can redistribute it and/or modify it
@@@ -95,8 -95,27 +95,27 @@@ void SD_init(int *argc, char **argv
    XBT_DEBUG("ADD SD LEVELS");
    SD_HOST_LEVEL = xbt_lib_add_level(host_lib,__SD_workstation_destroy);
    SD_LINK_LEVEL = xbt_lib_add_level(link_lib,__SD_link_destroy);
+   SD_STORAGE_LEVEL = xbt_lib_add_level(storage_lib,__SD_storage_destroy);
+   if (_sg_cfg_exit_asap) {
+     SD_exit();
+     exit(0);
+   }
  }
  
+ /** \brief set a configuration variable
+  *
+  * Do --help on any simgrid binary to see the list of currently existing configuration variables, and see Section @ref options.
+  *
+  * Example:
+  * SD_config("workstation/model","default");
+  */
+ void SD_config(const char *key, const char *value){
+   xbt_assert(sd_global,"ERROR: Please call SD_init() before using SD_config()");
+   xbt_cfg_set_as_string(_sg_cfg_set, key, value);
+ }
  /**
   * \brief Reinits the application part of the simulation (experimental feature)
   *
@@@ -191,10 -210,11 +210,11 @@@ void SD_create_environment(const char *
    char *name = NULL;
    void **surf_workstation = NULL;
    void **surf_link = NULL;
+   void **surf_storage = NULL;
  
    parse_platform_file(platform_file);
  
-   /* now let's create the SD wrappers for workstations and links */
+   /* now let's create the SD wrappers for workstations, storages and links */
    xbt_lib_foreach(host_lib, cursor, name, surf_workstation){
      if(surf_workstation[SURF_WKS_LEVEL])
        __SD_workstation_create(surf_workstation[SURF_WKS_LEVEL], NULL);
      __SD_link_create(surf_link[SURF_LINK_LEVEL], NULL);
    }
  
+   xbt_lib_foreach(storage_lib, cursor, name, surf_storage) {
+   if(surf_storage[SURF_STORAGE_LEVEL])
+     __SD_storage_create(surf_storage[SURF_STORAGE_LEVEL], NULL);
+   }
    XBT_DEBUG("Workstation number: %d, link number: %d",
           SD_workstation_get_number(), SD_link_get_number());
  #ifdef HAVE_JEDULE
@@@ -286,10 -312,11 +312,10 @@@ xbt_swag_t SD_simulate_swag(double how_
  
      /* let's see which tasks are done */
      xbt_dynar_foreach(model_list, iter, model) {
 -      while ((action = xbt_swag_extract(model->states.done_action_set))) {
 -        task = action->data;
 -        task->start_time =
 -            surf_workstation_model->
 -            action_get_start_time(task->surf_action);
 +      while ((action = xbt_swag_extract(surf_model_done_action_set(model)))) {
 +        task = surf_action_get_data(action);
 +        task->start_time = surf_action_get_start_time(task->surf_action);
 +
          task->finish_time = surf_get_clock();
          XBT_VERB("Task '%s' done", SD_task_get_name(task));
          XBT_DEBUG("Calling __SD_task_just_done");
        }
  
        /* let's see which tasks have just failed */
 -      while ((action = xbt_swag_extract(model->states.failed_action_set))) {
 -        task = action->data;
 -        task->start_time =
 -            surf_workstation_model->
 -            action_get_start_time(task->surf_action);
 +      while ((action = xbt_swag_extract(surf_model_failed_action_set(model)))) {
 +        task = surf_action_get_data(action);
 +        task->start_time = surf_action_get_start_time(task->surf_action);
          task->finish_time = surf_get_clock();
          XBT_VERB("Task '%s' failed", SD_task_get_name(task));
          __SD_task_set_state(task, SD_FAILED);
 -        surf_workstation_model->action_unref(action);
 +        surf_action_unref(action);
          task->surf_action = NULL;
  
          xbt_swag_insert(task,sd_global->return_set);
diff --combined src/simdag/sd_link.c
@@@ -1,4 -1,4 +1,4 @@@
- /* Copyright (c) 2006-2011. The SimGrid Team.
+ /* Copyright (c) 2006-2012. The SimGrid Team.
   * All rights reserved.                                                     */
  
  /* This program is free software; you can redistribute it and/or modify it
@@@ -23,7 -23,7 +23,7 @@@ SD_link_t __SD_link_create(void *surf_l
    link = xbt_new(s_SD_link_t, 1);
    link->surf_link = surf_link;
    link->data = data;            /* user data */
 -  if (surf_workstation_model->extension.workstation.link_shared(surf_link))
 +  if (surf_network_link_is_shared(surf_link))
      link->sharing_policy = SD_LINK_SHARED;
    else
      link->sharing_policy = SD_LINK_FATPIPE;
@@@ -118,7 -118,8 +118,7 @@@ const char *SD_link_get_name(SD_link_t 
   */
  double SD_link_get_current_bandwidth(SD_link_t link)
  {
 -  return surf_workstation_model->extension.workstation.
 -      get_link_bandwidth(link->surf_link);
 +  return surf_network_link_get_bandwidth(link->surf_link);
  }
  
  /**
   */
  double SD_link_get_current_latency(SD_link_t link)
  {
 -  return surf_workstation_model->extension.workstation.
 -      get_link_latency(link->surf_link);
 +  return surf_network_link_get_latency(link->surf_link);
  }
  
  /**
diff --combined src/simdag/sd_task.c
@@@ -1,4 -1,4 +1,4 @@@
- /* Copyright (c) 2006 - 2013. The SimGrid Team.
+ /* Copyright (c) 2006-2013. The SimGrid Team.
   * All rights reserved.                                                     */
  
  /* This program is free software; you can redistribute it and/or modify it
@@@ -172,8 -172,8 +172,8 @@@ return res
   * mandatory power.
   *
   * A parallel computation can be scheduled on any number of host.
-  * The underlying speedup model is Amdahl's law. 
-  * To be auto-scheduled, \see SD_task_distribute_comp_amdhal has to be called 
+  * The underlying speedup model is Amdahl's law.
+  * To be auto-scheduled, \see SD_task_distribute_comp_amdahl has to be called
   * first.
   * \param name the name of the task (can be \c NULL)
   * \param data the user data you want to associate with the task (can be \c NULL)
@@@ -257,7 -257,7 +257,7 @@@ void SD_task_destroy(SD_task_t task
    xbt_free(task->name);
  
    if (task->surf_action != NULL)
 -    surf_workstation_model->action_unref(task->surf_action);
 +      surf_action_unref(task->surf_action);
  
    xbt_free(task->workstation_list);
    xbt_free(task->communication_amount);
@@@ -358,11 -358,13 +358,11 @@@ void __SD_task_set_state(SD_task_t task
      break;
    case SD_RUNNING:
      task->state_set = sd_global->running_task_set;
 -    task->start_time =
 -        surf_workstation_model->action_get_start_time(task->surf_action);
 +    task->start_time = surf_action_get_start_time(task->surf_action);
      break;
    case SD_DONE:
      task->state_set = sd_global->done_task_set;
 -    task->finish_time =
 -        surf_workstation_model->action_get_finish_time(task->surf_action);
 +    task->finish_time = surf_action_get_finish_time(task->surf_action);
      task->remains = 0;
  #ifdef HAVE_JEDULE
      jedule_log_sd_event(task);
@@@ -474,7 -476,27 +474,27 @@@ double SD_task_get_amount(SD_task_t tas
  }
  
  /**
-  * \brief Returns the alpha parameter of a SD_TASK_COMP_PAR_AMDAH task
+  * \brief Sets the total amount of work of a task
+  * For sequential typed tasks (COMP_SEQ and COMM_E2E), it also sets the
+  * appropriate values in the computation_amount and communication_amount arrays
+  * respectively. Nothing more than modifying task->amount is done for paralle
+  * typed tasks (COMP_PAR_AMDAHL and COMM_PAR_MXN_1D_BLOCK) as the distribution
+  * of the amount of work is done at scheduling time.
+  *
+  * \param task a task
+  * \param amount the new amount of work to execute
+  */
+ void SD_task_set_amount(SD_task_t task, double amount)
+ {
+   task->amount = amount;
+   if (task->kind == SD_TASK_COMP_SEQ)
+     task->computation_amount[0] = amount;
+   if (task->kind == SD_TASK_COMM_E2E)
+     task->communication_amount[2] = amount;
+ }
+ /**
+  * \brief Returns the alpha parameter of a SD_TASK_COMP_PAR_AMDAHL task
   *
   * \param task a parallel task assuming Amdahl's law as speedup model
   * \return the alpha parameter (serial part of a task in percent) for this task
@@@ -497,7 -519,7 +517,7 @@@ double SD_task_get_alpha(SD_task_t task
  double SD_task_get_remaining_amount(SD_task_t task)
  {
    if (task->surf_action)
 -    return surf_workstation_model->get_remains(task->surf_action);
 +      return surf_action_get_remains(task->surf_action);
    else
      return task->remains;
  }
@@@ -1045,7 -1067,7 +1065,7 @@@ void SD_task_unschedule(SD_task_t task
    }
  
    if (__SD_task_is_running(task))       /* the task should become SD_FAILED */
 -    surf_workstation_model->action_cancel(task->surf_action);
 +      surf_action_cancel(task->surf_action);
    else {
      if (task->unsatisfied_dependencies == 0)
        __SD_task_set_state(task, SD_SCHEDULABLE);
@@@ -1112,7 -1134,7 +1132,7 @@@ void __SD_task_really_run(SD_task_t tas
    surf_workstations = xbt_new(void *, workstation_nb);
  
    for (i = 0; i < workstation_nb; i++)
 -    surf_workstations[i] = task->workstation_list[i];
 +    surf_workstations[i] =  surf_workstation_resource_priv(task->workstation_list[i]);
  
    double *computation_amount = xbt_new0(double, workstation_nb);
    double *communication_amount = xbt_new0(double, workstation_nb * workstation_nb);
      memcpy(communication_amount, task->communication_amount,
             sizeof(double) * workstation_nb * workstation_nb);
  
 -  task->surf_action =
 -        surf_workstation_model->extension.
 -        workstation.execute_parallel_task(workstation_nb,
 -                                          surf_workstations,
 -                                          computation_amount,
 -                                          communication_amount,
 -                                          task->rate);
 +  task->surf_action = surf_workstation_model_execute_parallel_task((surf_workstation_model_t)surf_workstation_model,
 +                                                                   workstation_nb,
 +                                                                   surf_workstations,
 +                                                                   computation_amount,
 +                                                                   communication_amount,
 +                                                                   task->rate);
  
 -  surf_workstation_model->action_data_set(task->surf_action, task);
 +  surf_action_set_data(task->surf_action, task);
  
    XBT_DEBUG("surf_action = %p", task->surf_action);
  
@@@ -1221,7 -1244,7 +1241,7 @@@ void __SD_task_just_done(SD_task_t task
    candidates = xbt_new(SD_task_t, 8);
  
    __SD_task_set_state(task, SD_DONE);
 -  surf_workstation_model->action_unref(task->surf_action);
 +  surf_action_unref(task->surf_action);
    task->surf_action = NULL;
  
    XBT_DEBUG("Looking for candidates");
@@@ -1379,7 -1402,8 +1399,7 @@@ static void __SD_task_remove_dependenci
  double SD_task_get_start_time(SD_task_t task)
  {
    if (task->surf_action)
 -    return surf_workstation_model->
 -        action_get_start_time(task->surf_action);
 +    return surf_action_get_start_time(task->surf_action);
    else
      return task->start_time;
  }
  double SD_task_get_finish_time(SD_task_t task)
  {
    if (task->surf_action)        /* should never happen as actions are destroyed right after their completion */
 -    return surf_workstation_model->
 -        action_get_finish_time(task->surf_action);
 +    return surf_action_get_finish_time(task->surf_action);
    else
      return task->finish_time;
  }
  /** @brief Blah
   *
   */
- void SD_task_distribute_comp_amdhal(SD_task_t task, int ws_count)
+ void SD_task_distribute_comp_amdahl(SD_task_t task, int ws_count)
  {
    int i;
    xbt_assert(task->kind == SD_TASK_COMP_PAR_AMDAHL,
@@@ -1457,7 -1482,7 +1477,7 @@@ void SD_task_schedulev(SD_task_t task, 
                SD_task_get_name(task));
    switch (task->kind) {
    case SD_TASK_COMP_PAR_AMDAHL:
-     SD_task_distribute_comp_amdhal(task, count);
+     SD_task_distribute_comp_amdahl(task, count);
    case SD_TASK_COMM_E2E:
    case SD_TASK_COMP_SEQ:
      xbt_assert(task->workstation_nb == count,
     * located (and start them if runnable) */
    if (task->kind == SD_TASK_COMP_PAR_AMDAHL) {
      XBT_VERB("Schedule computation task %s on %d workstations. %.f flops"
-              " will be distributed following Amdahl'Law",
+              " will be distributed following Amdahl'Law",
            SD_task_get_name(task), task->workstation_nb,
            task->computation_amount[0]);
      xbt_dynar_foreach(task->tasks_before, cpt, dep) {
@@@ -1,4 -1,4 +1,4 @@@
- /* Copyright (c) 2006-2011. The SimGrid Team.
+ /* Copyright (c) 2006-2013. The SimGrid Team.
   * All rights reserved.                                                     */
  
  /* This program is free software; you can redistribute it and/or modify it
@@@ -12,6 -12,8 +12,6 @@@
  #include "surf/surf.h"
  #include "surf/surf_resource.h"
  
 -
 -
  XBT_LOG_NEW_DEFAULT_SUBCATEGORY(sd_workstation, sd,
                                  "Logging specific to SimDag (workstation)");
  
@@@ -35,6 -37,32 +35,32 @@@ SD_workstation_t __SD_workstation_creat
    return xbt_lib_get_elm_or_null(host_lib,name);
  }
  
+ /* Creates a storage and registers it in SD.
+  */
+ SD_storage_t __SD_storage_create(void *surf_storage, void *data)
+ {
+   SD_storage_priv_t storage;
+   const char *name;
+   storage = xbt_new(s_SD_storage_priv_t, 1);
+   storage->data = data;     /* user data */
+   name = surf_resource_name(surf_storage);
+   xbt_lib_set(storage_lib,name, SD_STORAGE_LEVEL, storage);
+   return xbt_lib_get_elm_or_null(storage_lib, name);
+ }
+ /* Destroys a storage.
+  */
+ void __SD_storage_destroy(void *storage)
+ {
+   SD_storage_priv_t s;
+   s = (SD_storage_priv_t) storage;
+   xbt_free(s);
+ }
  /**
   * \brief Returns a workstation given its name
   *
@@@ -150,7 -178,8 +176,7 @@@ const char *SD_workstation_get_property
   */
  xbt_dict_t SD_workstation_get_properties(SD_workstation_t workstation)
  {
 -  return surf_workstation_model->extension.
 -      workstation.get_properties(surf_workstation_resource_priv(workstation));
 +  return surf_resource_get_properties(surf_workstation_resource_priv(workstation));
  }
  
  
@@@ -218,9 -247,9 +244,9 @@@ const SD_link_t *SD_route_get_list(SD_w
  
    surf_src = src;
    surf_dst = dst;
 -  surf_route =
 -      surf_workstation_model->extension.workstation.get_route(surf_src,
 -                                                              surf_dst);
 +
 +  surf_route = surf_workstation_model_get_route((surf_workstation_model_t)surf_workstation_model,
 +                                                      surf_src, surf_dst);
  
    xbt_dynar_foreach(surf_route, cpt, surf_link) {
      link_name = surf_resource_name(surf_link);
   */
  int SD_route_get_size(SD_workstation_t src, SD_workstation_t dst)
  {
 -  return xbt_dynar_length(surf_workstation_model->extension.
 -                          workstation.get_route(src, dst));
 +  return xbt_dynar_length(surf_workstation_model_get_route(
 +                  (surf_workstation_model_t)surf_workstation_model, src, dst));
  }
  
  /**
   */
  double SD_workstation_get_power(SD_workstation_t workstation)
  {
 -  return surf_workstation_model->extension.workstation.
 -      get_speed(workstation, 1.0);
 +  return surf_workstation_get_speed(workstation, 1.0);
  }
  
  /**
   */
  double SD_workstation_get_available_power(SD_workstation_t workstation)
  {
 -  return surf_workstation_model->extension.
 -      workstation.get_available_speed(workstation);
 +  return surf_workstation_get_available_speed(workstation);
  }
  
  /**
   *
   * \param workstation a workstation
   * \param computation_amount the computation amount you want to evaluate (in flops)
-  * \return an approximative astimated computation time for the given computation amount on this workstation (in seconds)
+  * \return an approximative estimated computation time for the given computation amount on this workstation (in seconds)
   */
  double SD_workstation_get_computation_time(SD_workstation_t workstation,
                                             double computation_amount)
@@@ -333,8 -364,7 +359,7 @@@ double SD_route_get_current_bandwidth(S
  
    links = SD_route_get_list(src, dst);
    nb_links = SD_route_get_size(src, dst);
-   bandwidth = min_bandwidth = -1.0;
+   min_bandwidth = -1.0;
  
    for (i = 0; i < nb_links; i++) {
      bandwidth = SD_link_get_current_bandwidth(links[i]);
   * \param src the first workstation
   * \param dst the second workstation
   * \param communication_amount the communication amount you want to evaluate (in bytes)
-  * \return an approximative astimated computation time for the given communication amount
+  * \return an approximative estimated computation time for the given communication amount
   * between the workstations (in seconds)
   */
  double SD_route_get_communication_time(SD_workstation_t src,
@@@ -445,6 -475,16 +470,16 @@@ void SD_workstation_set_access_mode(SD_
    }
  }
  
 -  return surf_workstation_model->extension.workstation.get_storage_list(workstation);
+ /**
+  * \brief Return the list of mounted storages on a workstation.
+  *
+  * \param workstation a workstation
+  * \return a dynar containing all mounted storages on the workstation
+  */
+ xbt_dict_t SD_workstation_get_storage_list(SD_workstation_t workstation){
++  return surf_workstation_get_storage_list(workstation);
+ }
  /* Returns whether a task can start now on a workstation*/
  /*
    int __SD_workstation_can_start(SD_workstation_t workstation, SD_task_t task) {
diff --combined src/simgrid/sg_config.c
@@@ -1,4 -1,4 +1,4 @@@
- /* Copyright (c) 2009, 2010. The SimGrid Team.
+ /* Copyright (c) 2009-2010, 2012-2013. The SimGrid Team.
   * All rights reserved.                                                     */
  
  /* This program is free software; you can redistribute it and/or modify it
@@@ -11,7 -11,7 +11,7 @@@
  #include "xbt/log.h"
  #include "xbt/mallocator.h"
  #include "xbt/str.h"
- #include "xbt/lib.h" 
+ #include "xbt/lib.h"
  #include "xbt/sysdep.h"
  #include "surf/surf.h"
  #include "surf/maxmin.h"
@@@ -27,10 -27,19 +27,19 @@@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_co
  
  xbt_cfg_t _sg_cfg_set = NULL;
  
- int _sg_init_status = 0;      /* 0: beginning of time (config cannot be changed yet);
-                                   1: initialized: cfg_set created (config can now be changed);
-                                   2: configured: command line parsed and config part of platform file was integrated also, platform construction ongoing or done.
-                                      (Config cannot be changed anymore!) */
+ /* 0: beginning of time (config cannot be changed yet);
+  * 1: initialized: cfg_set created (config can now be changed);
+  * 2: configured: command line parsed and config part of platform file was
+  *    integrated also, platform construction ongoing or done.
+  *    (Config cannot be changed anymore!)
+  */
+ int _sg_cfg_init_status = 0;
+ /* instruct the upper layer (simix or simdag) to exit as soon as possible
+  */
+ int _sg_cfg_exit_asap = 0;
+ #define sg_cfg_exit_early() do { _sg_cfg_exit_asap = 1; return; } while (0)
  
  /* Parse the command line, looking for options */
  static void sg_config_cmd_line(int *argc, char **argv)
      argv[j] = NULL;
      *argc = j;
    }
-   if (shall_exit) {
-     _sg_init_status=1; // get everything cleanly cleaned on exit
-     exit(0);
-   }
+   if (shall_exit)
+     sg_cfg_exit_early();
  }
  
  /* callback of the workstation/model variable */
@@@ -104,14 -111,14 +111,14 @@@ static void _sg_cfg_cb__workstation_mod
  {
    char *val;
  
-   xbt_assert(_sg_init_status == 1,
+   xbt_assert(_sg_cfg_init_status < 2,
                "Cannot change the model after the initialization");
  
    val = xbt_cfg_get_string(_sg_cfg_set, name);
  
    if (!strcmp(val, "help")) {
      model_help("workstation", surf_workstation_model_description);
-     exit(0);
+     sg_cfg_exit_early();
    }
  
    /* Make sure that the model exists */
@@@ -123,14 -130,14 +130,14 @@@ static void _sg_cfg_cb__cpu_model(cons
  {
    char *val;
  
-   xbt_assert(_sg_init_status == 1,
+   xbt_assert(_sg_cfg_init_status < 2,
                "Cannot change the model after the initialization");
  
    val = xbt_cfg_get_string(_sg_cfg_set, name);
  
    if (!strcmp(val, "help")) {
      model_help("CPU", surf_cpu_model_description);
-     exit(0);
+     sg_cfg_exit_early();
    }
  
    /* New Module missing */
@@@ -142,14 -149,14 +149,14 @@@ static void _sg_cfg_cb__optimization_mo
  {
    char *val;
  
-   xbt_assert(_sg_init_status == 1,
+   xbt_assert(_sg_cfg_init_status < 2,
                "Cannot change the model after the initialization");
  
    val = xbt_cfg_get_string(_sg_cfg_set, name);
  
    if (!strcmp(val, "help")) {
      model_help("optimization", surf_optimization_mode_description);
-     exit(0);
+     sg_cfg_exit_early();
    }
  
    /* New Module missing */
@@@ -161,14 -168,14 +168,14 @@@ static void _sg_cfg_cb__storage_mode(co
  {
    char *val;
  
-   xbt_assert(_sg_init_status == 1,
+   xbt_assert(_sg_cfg_init_status < 2,
                "Cannot change the model after the initialization");
  
    val = xbt_cfg_get_string(_sg_cfg_set, name);
  
    if (!strcmp(val, "help")) {
      model_help("storage", surf_storage_model_description);
-     exit(0);
+     sg_cfg_exit_early();
    }
  
    /* New Module missing */
@@@ -180,21 -187,20 +187,20 @@@ static void _sg_cfg_cb__network_model(c
  {
    char *val;
  
-   xbt_assert(_sg_init_status == 1,
+   xbt_assert(_sg_cfg_init_status < 2,
                "Cannot change the model after the initialization");
  
    val = xbt_cfg_get_string(_sg_cfg_set, name);
  
    if (!strcmp(val, "help")) {
      model_help("network", surf_network_model_description);
-     exit(0);
+     sg_cfg_exit_early();
    }
  
    /* New Module missing */
    find_model_description(surf_network_model_description, val);
  }
  
  /* callbacks of the network models values */
  static void _sg_cfg_cb__tcp_gamma(const char *name, int pos)
  {
@@@ -229,19 -235,19 +235,19 @@@ static void _sg_cfg_cb__weight_S(const 
  #ifdef HAVE_SMPI
  /* callback of the mpi collectives */
  static void _sg_cfg_cb__coll(const char *category,
-                            s_mpi_coll_description_t * table,
-                            const char *name, int pos)
+                              s_mpi_coll_description_t * table,
+                              const char *name, int pos)
  {
    char *val;
  
-   xbt_assert(_sg_init_status == 1,
+   xbt_assert(_sg_cfg_init_status < 2,
                "Cannot change the model after the initialization");
  
    val = xbt_cfg_get_string(_sg_cfg_set, name);
  
    if (!strcmp(val, "help")) {
      coll_help(category, table);
-     exit(0);
+     sg_cfg_exit_early();
    }
  
    /* New Module missing */
@@@ -262,19 -268,19 +268,19 @@@ static void _sg_cfg_cb__coll_allreduce(
  }
  static void _sg_cfg_cb__coll_alltoall(const char *name, int pos)
  {
-   _sg_cfg_cb__coll("alltoall", mpi_coll_alltoall_description, name, pos);  
+   _sg_cfg_cb__coll("alltoall", mpi_coll_alltoall_description, name, pos);
  }
  static void _sg_cfg_cb__coll_alltoallv(const char *name, int pos)
  {
-   _sg_cfg_cb__coll("alltoallv", mpi_coll_alltoallv_description, name, pos);  
+   _sg_cfg_cb__coll("alltoallv", mpi_coll_alltoallv_description, name, pos);
  }
  static void _sg_cfg_cb__coll_bcast(const char *name, int pos)
  {
-   _sg_cfg_cb__coll("bcast", mpi_coll_bcast_description, name, pos);  
+   _sg_cfg_cb__coll("bcast", mpi_coll_bcast_description, name, pos);
  }
  static void _sg_cfg_cb__coll_reduce(const char *name, int pos)
  {
-   _sg_cfg_cb__coll("reduce", mpi_coll_reduce_description, name, pos);  
+   _sg_cfg_cb__coll("reduce", mpi_coll_reduce_description, name, pos);
  }
  static void _sg_cfg_cb__coll_reduce_scatter(const char *name, int pos){
    _sg_cfg_cb__coll("reduce_scatter", mpi_coll_reduce_scatter_description, name, pos);
@@@ -318,8 -324,15 +324,15 @@@ static void _sg_cfg_cb_verbose_exit(con
    _sg_do_verbose_exit = xbt_cfg_get_boolean(_sg_cfg_set, name);
  }
  
+ extern int _sg_do_clean_atexit;
  
- static void _sg_cfg_cb_context_factory(const char *name, int pos) {
+ static void _sg_cfg_cb_clean_atexit(const char *name, int pos)
+ {
+   _sg_do_clean_atexit = xbt_cfg_get_boolean(_sg_cfg_set, name);
+ }
+ static void _sg_cfg_cb_context_factory(const char *name, int pos)
+ {
    smx_context_factory_name = xbt_cfg_get_string(_sg_cfg_set, name);
  }
  
@@@ -353,12 -366,12 +366,12 @@@ static void _sg_cfg_cb_contexts_paralle
    }
    else {
      xbt_die("Command line setting of the parallel synchronization mode should "
-         "be one of \"posix\", \"futex\" or \"busy_wait\"");
+             "be one of \"posix\", \"futex\" or \"busy_wait\"");
    }
  }
  
  static void _sg_cfg_cb__surf_network_coordinates(const char *name,
-                                                    int pos)
+                                                  int pos)
  {
    int val = xbt_cfg_get_boolean(_sg_cfg_set, name);
    if (val) {
@@@ -392,14 -405,12 +405,12 @@@ static void _sg_cfg_cb__gtnets_jitter_s
  /* create the config set, register what should be and parse the command line*/
  void sg_config_init(int *argc, char **argv)
  {
-   char *description = xbt_malloc(1024), *p = description;
-   char *default_value;
-   double double_default_value;
-   int default_value_int;
+   char *description = xbt_malloc(1024);
+   char *p;
    int i;
  
    /* Create the configuration support */
-   if (_sg_init_status == 0) { /* Only create stuff if not already inited */
+   if (_sg_cfg_init_status == 0) { /* Only create stuff if not already inited */
      sprintf(description,
              "The model to use for the CPU. Possible values: ");
      p = description;
                     surf_cpu_model_description[i].name);
      sprintf(p,
              ".\n       (use 'help' as a value to see the long description of each model)");
-     default_value = xbt_strdup("Cas01");
-     xbt_cfg_register(&_sg_cfg_set, "cpu/model", description, xbt_cfgelm_string,
-                      &default_value, 1, 1, &_sg_cfg_cb__cpu_model, NULL);
+     xbt_cfg_register(&_sg_cfg_set, "cpu/model", description,
+                      xbt_cfgelm_string, 1, 1, &_sg_cfg_cb__cpu_model, NULL);
+     xbt_cfg_setdefault_string(_sg_cfg_set, "cpu/model", "Cas01");
  
-     sprintf(description,
-             "The optimization modes to use for the CPU. Possible values: ");
-     p = description;
      while (*(++p) != '\0');
      for (i = 0; surf_optimization_mode_description[i].name; i++)
        p += sprintf(p, "%s%s", (i == 0 ? "" : ", "),
                     surf_optimization_mode_description[i].name);
      sprintf(p,
              ".\n       (use 'help' as a value to see the long description of each optimization mode)");
-     default_value = xbt_strdup("Lazy");
-     xbt_cfg_register(&_sg_cfg_set, "cpu/optim", description, xbt_cfgelm_string,
-                      &default_value, 1, 1, &_sg_cfg_cb__optimization_mode, NULL);
+     xbt_cfg_register(&_sg_cfg_set, "cpu/optim", description,
+                      xbt_cfgelm_string, 1, 1, &_sg_cfg_cb__optimization_mode, NULL);
+     xbt_cfg_setdefault_string(_sg_cfg_set, "cpu/optim", "Lazy");
  
      sprintf(description,
              "The model to use for the storage. Possible values: ");
                     surf_storage_model_description[i].name);
      sprintf(p,
              ".\n       (use 'help' as a value to see the long description of each model)");
-     default_value = xbt_strdup("default");
-     xbt_cfg_register(&_sg_cfg_set, "storage/model", description, xbt_cfgelm_string,
-                      &default_value, 1, 1, &_sg_cfg_cb__storage_mode,
-                      NULL);
+     xbt_cfg_register(&_sg_cfg_set, "storage/model", description,
+                      xbt_cfgelm_string, 1, 1, &_sg_cfg_cb__storage_mode, NULL);
+     xbt_cfg_setdefault_string(_sg_cfg_set, "storage/model", "default");
  
 -    /* ********************************************************************* */
 -    /* TUTORIAL: New model                                                   */
 -    sprintf(description,
 -            "The model to use for the New model. Possible values: ");
 -    p = description;
 -    while (*(++p) != '\0');
 -    for (i = 0; surf_new_model_description[i].name; i++)
 -      p += sprintf(p, "%s%s", (i == 0 ? "" : ", "),
 -                   surf_new_model_description[i].name);
 -    sprintf(p,
 -            ".\n       (use 'help' as a value to see the long description of each model)");
 -    xbt_cfg_register(&_sg_cfg_set, "new_model/model", description,
 -                     xbt_cfgelm_string, 1, 1, &_sg_cfg_cb__storage_mode, NULL);
 -    xbt_cfg_setdefault_string(_sg_cfg_set, "new_model/model", "default");
 -    /* ********************************************************************* */
 -
      sprintf(description,
              "The model to use for the network. Possible values: ");
      p = description;
                     surf_network_model_description[i].name);
      sprintf(p,
              ".\n       (use 'help' as a value to see the long description of each model)");
-     default_value = xbt_strdup("LV08");
-     xbt_cfg_register(&_sg_cfg_set, "network/model", description, xbt_cfgelm_string,
-                      &default_value, 1, 1, &_sg_cfg_cb__network_model,
-                      NULL);
+     xbt_cfg_register(&_sg_cfg_set, "network/model", description,
+                      xbt_cfgelm_string, 1, 1, &_sg_cfg_cb__network_model, NULL);
+     xbt_cfg_setdefault_string(_sg_cfg_set, "network/model", "LV08");
  
      sprintf(description,
              "The optimization modes to use for the network. Possible values: ");
                     surf_optimization_mode_description[i].name);
      sprintf(p,
              ".\n       (use 'help' as a value to see the long description of each optimization mode)");
-     default_value = xbt_strdup("Lazy");
-     xbt_cfg_register(&_sg_cfg_set, "network/optim", description, xbt_cfgelm_string,
-                      &default_value, 1, 1, &_sg_cfg_cb__optimization_mode, NULL);
+     xbt_cfg_register(&_sg_cfg_set, "network/optim", description,
+                      xbt_cfgelm_string, 1, 1, &_sg_cfg_cb__optimization_mode, NULL);
+     xbt_cfg_setdefault_string(_sg_cfg_set, "network/optim", "Lazy");
  
      sprintf(description,
              "The model to use for the workstation. Possible values: ");
                     surf_workstation_model_description[i].name);
      sprintf(p,
              ".\n       (use 'help' as a value to see the long description of each model)");
-     default_value = xbt_strdup("default");
-     xbt_cfg_register(&_sg_cfg_set, "workstation/model", description, xbt_cfgelm_string,
-                      &default_value, 1, 1,
-                      &_sg_cfg_cb__workstation_model, NULL);
-     xbt_free(description);
+     xbt_cfg_register(&_sg_cfg_set, "workstation/model", description,
+                      xbt_cfgelm_string, 1, 1, &_sg_cfg_cb__workstation_model, NULL);
+     xbt_cfg_setdefault_string(_sg_cfg_set, "workstation/model", "default");
  
      xbt_cfg_register(&_sg_cfg_set, "network/TCP_gamma",
                       "Size of the biggest TCP window (cat /proc/sys/net/ipv4/tcp_[rw]mem for recv/send window; Use the last given value, which is the max window size)",
-                      xbt_cfgelm_double, NULL, 1, 1,
-                      _sg_cfg_cb__tcp_gamma, NULL);
+                      xbt_cfgelm_double, 1, 1, _sg_cfg_cb__tcp_gamma, NULL);
      xbt_cfg_setdefault_double(_sg_cfg_set, "network/TCP_gamma", 4194304.0);
  
      xbt_cfg_register(&_sg_cfg_set, "maxmin/precision",
                       "Numerical precision used when updating simulation models (epsilon in double comparisons)",
-                      xbt_cfgelm_double, NULL, 1, 1, _sg_cfg_cb__maxmin_precision, NULL);
-     xbt_cfg_setdefault_double(_sg_cfg_set, "maxmin/precision", 0.00001); 
+                      xbt_cfgelm_double, 1, 1, _sg_cfg_cb__maxmin_precision, NULL);
+     xbt_cfg_setdefault_double(_sg_cfg_set, "maxmin/precision", 0.00001);
  
      /* The parameters of network models */
  
      xbt_cfg_register(&_sg_cfg_set, "network/sender_gap",
                       "Minimum gap between two overlapping sends",
-                      xbt_cfgelm_double, NULL, 1, 1, /* default is set in network.c */
-                      _sg_cfg_cb__sender_gap, NULL);
+                      xbt_cfgelm_double, 1, 1, _sg_cfg_cb__sender_gap, NULL);
+     /* default for "network/sender_gap" is set in network.c */
  
-     double_default_value = 1.0; // FIXME use setdefault everywhere here!
      xbt_cfg_register(&_sg_cfg_set, "network/latency_factor",
                       "Correction factor to apply to the provided latency (default value set by network model)",
-                      xbt_cfgelm_double, &double_default_value, 1, 1,
-                      _sg_cfg_cb__latency_factor, NULL);
-     double_default_value = 1.0;
+                      xbt_cfgelm_double, 1, 1, _sg_cfg_cb__latency_factor, NULL);
+     xbt_cfg_setdefault_double(_sg_cfg_set, "network/latency_factor", 1.0);
      xbt_cfg_register(&_sg_cfg_set, "network/bandwidth_factor",
                       "Correction factor to apply to the provided bandwidth (default value set by network model)",
-                      xbt_cfgelm_double, &double_default_value, 1, 1,
-                      _sg_cfg_cb__bandwidth_factor, NULL);
+                      xbt_cfgelm_double, 1, 1, _sg_cfg_cb__bandwidth_factor, NULL);
+     xbt_cfg_setdefault_double(_sg_cfg_set, "network/bandwidth_factor", 1.0);
  
      xbt_cfg_register(&_sg_cfg_set, "network/weight_S",
                       "Correction factor to apply to the weight of competing streams (default value set by network model)",
-                      xbt_cfgelm_double, NULL, 1, 1, /* default is set in network.c */
-                      _sg_cfg_cb__weight_S, NULL);
+                      xbt_cfgelm_double, 1, 1, _sg_cfg_cb__weight_S, NULL);
+     /* default for "network/weight_S" is set in network.c */
  
      /* Inclusion path */
      xbt_cfg_register(&_sg_cfg_set, "path",
                       "Lookup path for inclusions in platform and deployment XML files",
-                      xbt_cfgelm_string, NULL, 0, 0,
-                      _sg_cfg_cb__surf_path, NULL);
+                      xbt_cfgelm_string, 0, 0, _sg_cfg_cb__surf_path, NULL);
  
-     default_value = xbt_strdup("off");
      xbt_cfg_register(&_sg_cfg_set, "cpu/maxmin_selective_update",
                       "Update the constraint set propagating recursively to others constraints (off by default when optim is set to lazy)",
-                      xbt_cfgelm_boolean, &default_value, 0, 1,
-                      NULL, NULL);
-     default_value = xbt_strdup("off");
+                      xbt_cfgelm_boolean, 0, 1, NULL, NULL);
+     xbt_cfg_setdefault_boolean(_sg_cfg_set, "cpu/maxmin_selective_update", "no");
      xbt_cfg_register(&_sg_cfg_set, "network/maxmin_selective_update",
                       "Update the constraint set propagating recursively to others constraints (off by default when optim is set to lazy)",
-                      xbt_cfgelm_boolean, &default_value, 0, 1,
-                      NULL, NULL);
+                      xbt_cfgelm_boolean, 0, 1, NULL, NULL);
+     xbt_cfg_setdefault_boolean(_sg_cfg_set, "network/maxmin_selective_update", "no");
  
  #ifdef HAVE_MC
      /* do model-checking */
-     default_value = xbt_strdup("off");
      xbt_cfg_register(&_sg_cfg_set, "model-check",
                       "Verify the system through model-checking instead of simulating it (EXPERIMENTAL)",
-                      xbt_cfgelm_boolean, NULL, 0, 1,
-                      _sg_cfg_cb_model_check, NULL);
-     xbt_cfg_setdefault_boolean(_sg_cfg_set, "model-check", default_value);
+                      xbt_cfgelm_boolean, 0, 1, _sg_cfg_cb_model_check, NULL);
+     xbt_cfg_setdefault_boolean(_sg_cfg_set, "model-check", "no");
  
      /* do stateful model-checking */
-     default_value = xbt_strdup("off");
      xbt_cfg_register(&_sg_cfg_set, "model-check/checkpoint",
-                      "Specify the amount of steps between checkpoints during stateful model-checking (default: off => stateless verification). "
+                      "Specify the amount of steps between checkpoints during stateful model-checking (default: 0 => stateless verification). "
                       "If value=on, one checkpoint is saved for each step => faster verification, but huge memory consumption; higher values are good compromises between speed and memory consumption.",
-                      xbt_cfgelm_boolean, NULL, 0, 1,
-                      _mc_cfg_cb_checkpoint, NULL);
-     xbt_cfg_setdefault_boolean(_sg_cfg_set, "model-check/checkpoint", default_value);
-     
+                      xbt_cfgelm_int, 0, 1, _mc_cfg_cb_checkpoint, NULL);
+     xbt_cfg_setdefault_int(_sg_cfg_set, "model-check/checkpoint", 0);
      /* do liveness model-checking */
      xbt_cfg_register(&_sg_cfg_set, "model-check/property",
                       "Specify the name of the file containing the property. It must be the result of the ltl2ba program.",
-                      xbt_cfgelm_string, NULL, 0, 1,
-                      _mc_cfg_cb_property, NULL);
+                      xbt_cfgelm_string, 0, 1, _mc_cfg_cb_property, NULL);
      xbt_cfg_setdefault_string(_sg_cfg_set, "model-check/property", "");
  
      /* Specify the kind of model-checking reduction */
      xbt_cfg_register(&_sg_cfg_set, "model-check/reduction",
                       "Specify the kind of exploration reduction (either none or DPOR)",
-                      xbt_cfgelm_string, NULL, 0, 1,
-                      _mc_cfg_cb_reduce, NULL);
+                      xbt_cfgelm_string, 0, 1, _mc_cfg_cb_reduce, NULL);
      xbt_cfg_setdefault_string(_sg_cfg_set, "model-check/reduction", "dpor");
  
      /* Enable/disable timeout for wait requests with model-checking */
-     default_value = xbt_strdup("off");
      xbt_cfg_register(&_sg_cfg_set, "model-check/timeout",
                       "Enable/Disable timeout for wait requests",
-                      xbt_cfgelm_boolean, NULL, 0, 1,
-                      _mc_cfg_cb_timeout, NULL);
-     xbt_cfg_setdefault_boolean(_sg_cfg_set, "model-check/timeout", default_value);
+                      xbt_cfgelm_boolean, 0, 1, _mc_cfg_cb_timeout, NULL);
+     xbt_cfg_setdefault_boolean(_sg_cfg_set, "model-check/timeout", "no");
  
      /* Set max depth exploration */
      xbt_cfg_register(&_sg_cfg_set, "model-check/max_depth",
                       "Specify the max depth of exploration (default : 1000)",
-                      xbt_cfgelm_int, NULL, 0, 1,
-                      _mc_cfg_cb_max_depth, NULL);
+                      xbt_cfgelm_int, 0, 1, _mc_cfg_cb_max_depth, NULL);
      xbt_cfg_setdefault_int(_sg_cfg_set, "model-check/max_depth", 1000);
  
      /* Set number of visited state stored for state comparison reduction*/
      xbt_cfg_register(&_sg_cfg_set, "model-check/visited",
                       "Specify the number of visited state stored for state comparison reduction. If value=5, the last 5 visited states are stored",
-                      xbt_cfgelm_int, NULL, 0, 1,
-                      _mc_cfg_cb_visited, NULL);
+                      xbt_cfgelm_int, 0, 1, _mc_cfg_cb_visited, NULL);
      xbt_cfg_setdefault_int(_sg_cfg_set, "model-check/visited", 0);
  
      /* Set file name for dot output of graph state */
      xbt_cfg_register(&_sg_cfg_set, "model-check/dot_output",
                       "Specify the name of dot file corresponding to graph state",
-                      xbt_cfgelm_string, NULL, 0, 1,
-                      _mc_cfg_cb_dot_output, NULL);
+                      xbt_cfgelm_string, 0, 1, _mc_cfg_cb_dot_output, NULL);
      xbt_cfg_setdefault_string(_sg_cfg_set, "model-check/dot_output", "");
  #endif
  
      /* do verbose-exit */
-     default_value = xbt_strdup("on");
      xbt_cfg_register(&_sg_cfg_set, "verbose-exit",
                       "Activate the \"do nothing\" mode in Ctrl-C",
-                      xbt_cfgelm_boolean, &default_value, 0, 1,
-                      _sg_cfg_cb_verbose_exit, NULL);
-     
-     
+                      xbt_cfgelm_boolean, 0, 1, _sg_cfg_cb_verbose_exit, NULL);
+     xbt_cfg_setdefault_boolean(_sg_cfg_set, "verbose-exit", "yes");
      /* context factory */
-     default_value = xbt_strdup("ucontext");
-     xbt_cfg_register(&_sg_cfg_set, "contexts/factory",
-                      "Context factory to use in SIMIX (ucontext, thread or raw)",
-                      xbt_cfgelm_string, &default_value, 1, 1, _sg_cfg_cb_context_factory, NULL);
+     sprintf(description,
+             "Context factory to use in SIMIX. Possible values: thread");
+     const char *dflt_ctx_fact = "thread";
+ #ifdef CONTEXT_UCONTEXT
+     strcat(description, ", ucontext");
+     dflt_ctx_fact = "ucontext";
+ #endif
+ #ifdef HAVE_RAWCTX
+     strcat(description, ", raw");
+     dflt_ctx_fact = "raw";
+ #endif
+     strcat(description, ".");
+     xbt_cfg_register(&_sg_cfg_set, "contexts/factory", description,
+                      xbt_cfgelm_string, 1, 1, _sg_cfg_cb_context_factory, NULL);
+     xbt_cfg_setdefault_string(_sg_cfg_set, "contexts/factory", dflt_ctx_fact);
  
      /* stack size of contexts in Ko */
-     default_value_int = 128;
      xbt_cfg_register(&_sg_cfg_set, "contexts/stack_size",
-                      "Stack size of contexts in Kib (ucontext or raw only)",
-                      xbt_cfgelm_int, &default_value_int, 1, 1,
-                      _sg_cfg_cb_context_stack_size, NULL);
+                      "Stack size of contexts in Kib",
+                      xbt_cfgelm_int, 1, 1, _sg_cfg_cb_context_stack_size, NULL);
+     xbt_cfg_setdefault_int(_sg_cfg_set, "contexts/stack_size", 128);
  
      /* number of parallel threads for user processes */
-     default_value_int = 1;
      xbt_cfg_register(&_sg_cfg_set, "contexts/nthreads",
                       "Number of parallel threads used to execute user contexts",
-                      xbt_cfgelm_int, &default_value_int, 1, 1,
-                      _sg_cfg_cb_contexts_nthreads, NULL);
+                      xbt_cfgelm_int, 1, 1, _sg_cfg_cb_contexts_nthreads, NULL);
+     xbt_cfg_setdefault_int(_sg_cfg_set, "contexts/nthreads", 1);
  
      /* minimal number of user contexts to be run in parallel */
-     default_value_int = 2;
      xbt_cfg_register(&_sg_cfg_set, "contexts/parallel_threshold",
-         "Minimal number of user contexts to be run in parallel (raw contexts only)",
-         xbt_cfgelm_int, &default_value_int, 1, 1,
-         _sg_cfg_cb_contexts_parallel_threshold, NULL);
+                      "Minimal number of user contexts to be run in parallel (raw contexts only)",
+                      xbt_cfgelm_int, 1, 1, _sg_cfg_cb_contexts_parallel_threshold, NULL);
+     xbt_cfg_setdefault_int(_sg_cfg_set, "contexts/parallel_threshold", 2);
  
      /* synchronization mode for parallel user contexts */
+     xbt_cfg_register(&_sg_cfg_set, "contexts/synchro",
+                      "Synchronization mode to use when running contexts in parallel (either futex, posix or busy_wait)",
+                      xbt_cfgelm_string, 1, 1, _sg_cfg_cb_contexts_parallel_mode, NULL);
  #ifdef HAVE_FUTEX_H
-     default_value = xbt_strdup("futex");
+     xbt_cfg_setdefault_string(_sg_cfg_set, "contexts/synchro", "futex");
  #else //No futex on mac and posix is unimplememted yet
-     default_value = xbt_strdup("busy_wait");
+     xbt_cfg_setdefault_string(_sg_cfg_set, "contexts/synchro", "busy_wait");
  #endif
-     xbt_cfg_register(&_sg_cfg_set, "contexts/synchro",
-         "Synchronization mode to use when running contexts in parallel (either futex, posix or busy_wait)",
-         xbt_cfgelm_string, &default_value, 1, 1,
-         _sg_cfg_cb_contexts_parallel_mode, NULL);
  
-     default_value = xbt_strdup("no");
      xbt_cfg_register(&_sg_cfg_set, "network/coordinates",
                       "\"yes\" or \"no\", specifying whether we use a coordinate-based routing (as Vivaldi)",
-                      xbt_cfgelm_boolean, &default_value, 1, 1,
-                      _sg_cfg_cb__surf_network_coordinates, NULL);
-     xbt_cfg_setdefault_boolean(_sg_cfg_set, "network/coordinates", default_value);
+                      xbt_cfgelm_boolean, 1, 1, _sg_cfg_cb__surf_network_coordinates, NULL);
+     xbt_cfg_setdefault_boolean(_sg_cfg_set, "network/coordinates", "no");
  
-     default_value = xbt_strdup("no");
      xbt_cfg_register(&_sg_cfg_set, "network/crosstraffic",
                       "Activate the interferences between uploads and downloads for fluid max-min models (LV08, CM02)",
-                      xbt_cfgelm_boolean, &default_value, 0, 1,
-                      _sg_cfg_cb__surf_network_crosstraffic, NULL);
-     xbt_cfg_setdefault_boolean(_sg_cfg_set, "network/crosstraffic", default_value);
+                      xbt_cfgelm_boolean, 0, 1, _sg_cfg_cb__surf_network_crosstraffic, NULL);
+     xbt_cfg_setdefault_boolean(_sg_cfg_set, "network/crosstraffic", "no");
  
  #ifdef HAVE_GTNETS
      xbt_cfg_register(&_sg_cfg_set, "gtnets/jitter",
                       "Double value to oscillate the link latency, uniformly in random interval [-latency*gtnets_jitter,latency*gtnets_jitter)",
-                      xbt_cfgelm_double, NULL, 1, 1,
-                      _sg_cfg_cb__gtnets_jitter, NULL);
+                      xbt_cfgelm_double, 1, 1, _sg_cfg_cb__gtnets_jitter, NULL);
      xbt_cfg_setdefault_double(_sg_cfg_set, "gtnets/jitter", 0.0);
  
-     default_value_int = 10;
      xbt_cfg_register(&_sg_cfg_set, "gtnets/jitter_seed",
                       "Use a positive seed to reproduce jitted results, value must be in [1,1e8], default is 10",
-                      xbt_cfgelm_int, &default_value_int, 0, 1,
-                      _sg_cfg_cb__gtnets_jitter_seed, NULL);
+                      xbt_cfgelm_int, 0, 1, _sg_cfg_cb__gtnets_jitter_seed, NULL);
+     xbt_cfg_setdefault_int(_sg_cfg_set, "gtnets/jitter_seed", 10);
  #endif
  #ifdef HAVE_NS3
      xbt_cfg_register(&_sg_cfg_set, "ns3/TcpModel",
                       "The ns3 tcp model can be : NewReno or Reno or Tahoe",
-                      xbt_cfgelm_string, NULL, 1, 1,
-                      NULL, NULL);
+                      xbt_cfgelm_string, 1, 1, NULL, NULL);
      xbt_cfg_setdefault_string(_sg_cfg_set, "ns3/TcpModel", "default");
  #endif
  
  #ifdef HAVE_SMPI
-     double default_reference_speed = 20000.0;
      xbt_cfg_register(&_sg_cfg_set, "smpi/running_power",
                       "Power of the host running the simulation (in flop/s). Used to bench the operations.",
-                      xbt_cfgelm_double, &default_reference_speed, 1, 1, NULL,
-                      NULL);
+                      xbt_cfgelm_double, 1, 1, NULL, NULL);
+     xbt_cfg_setdefault_double(_sg_cfg_set, "smpi/running_power", 20000.0);
  
-     default_value = xbt_strdup("no");
      xbt_cfg_register(&_sg_cfg_set, "smpi/display_timing",
                       "Boolean indicating whether we should display the timing after simulation.",
-                      xbt_cfgelm_boolean, &default_value, 1, 1, NULL,
-                      NULL);
-     xbt_cfg_setdefault_boolean(_sg_cfg_set, "smpi/display_timing", default_value);
+                      xbt_cfgelm_boolean, 1, 1, NULL, NULL);
+     xbt_cfg_setdefault_boolean(_sg_cfg_set, "smpi/display_timing", "no");
+     xbt_cfg_register(&_sg_cfg_set, "smpi/use_shared_malloc",
+                      "Boolean indicating whether we should use shared memory when using SMPI_SHARED_MALLOC. Allows user to disable it for debug purposes.",
+                      xbt_cfgelm_boolean, 1, 1, NULL, NULL);
+     xbt_cfg_setdefault_boolean(_sg_cfg_set, "smpi/use_shared_malloc", "yes");
  
-     double default_threshold = 1e-6;
      xbt_cfg_register(&_sg_cfg_set, "smpi/cpu_threshold",
                       "Minimal computation time (in seconds) not discarded.",
-                      xbt_cfgelm_double, &default_threshold, 1, 1, NULL,
-                      NULL);
+                      xbt_cfgelm_double, 1, 1, NULL, NULL);
+     xbt_cfg_setdefault_double(_sg_cfg_set, "smpi/cpu_threshold", 1e-6);
  
-     int default_small_messages_threshold = 0;
      xbt_cfg_register(&_sg_cfg_set, "smpi/async_small_thres",
                       "Maximal size of messages that are to be sent asynchronously, without waiting for the receiver",
-                      xbt_cfgelm_int, &default_small_messages_threshold, 1, 1, NULL,
-                      NULL);
+                      xbt_cfgelm_int, 1, 1, NULL, NULL);
+     xbt_cfg_setdefault_int(_sg_cfg_set, "smpi/async_small_thres", 0);
  
-     int default_send_is_detached_threshold = 65536;
      xbt_cfg_register(&_sg_cfg_set, "smpi/send_is_detached_thres",
                       "Threshold of message size where MPI_Send stops behaving like MPI_Isend and becomes MPI_Ssend",
-                      xbt_cfgelm_int, &default_send_is_detached_threshold, 1, 1, NULL,
-                      NULL);
+                      xbt_cfgelm_int, 1, 1, NULL, NULL);
+     xbt_cfg_setdefault_int(_sg_cfg_set, "smpi/send_is_detached_thres", 65536);
  
      //For smpi/bw_factor and smpi/lat_factor
      //Default value have to be "threshold0:value0;threshold1:value1;...;thresholdN:valueN"
      //  or with tag config put line <prop id="smpi/bw_factor" value="threshold0:value0;threshold1:value1;...;thresholdN:valueN"></prop>
      xbt_cfg_register(&_sg_cfg_set, "smpi/bw_factor",
                       "Bandwidth factors for smpi.",
-                      xbt_cfgelm_string, NULL, 1, 1, NULL,
-                      NULL);
+                      xbt_cfgelm_string, 1, 1, NULL, NULL);
      xbt_cfg_setdefault_string(_sg_cfg_set, "smpi/bw_factor", "65472:0.940694;15424:0.697866;9376:0.58729;5776:1.08739;3484:0.77493;1426:0.608902;732:0.341987;257:0.338112;0:0.812084");
  
      xbt_cfg_register(&_sg_cfg_set, "smpi/lat_factor",
                       "Latency factors for smpi.",
-                      xbt_cfgelm_string, NULL, 1, 1, NULL,
-                      NULL);
+                      xbt_cfgelm_string, 1, 1, NULL, NULL);
      xbt_cfg_setdefault_string(_sg_cfg_set, "smpi/lat_factor", "65472:11.6436;15424:3.48845;9376:2.59299;5776:2.18796;3484:1.88101;1426:1.61075;732:1.9503;257:1.95341;0:2.01467");
  
      xbt_cfg_register(&_sg_cfg_set, "smpi/os",
                       "Small messages timings (MPI_Send minimum time for small messages)",
-                      xbt_cfgelm_string, NULL, 1, 1, NULL,
-                      NULL);
+                      xbt_cfgelm_string, 1, 1, NULL, NULL);
      xbt_cfg_setdefault_string(_sg_cfg_set, "smpi/os", "1:0:0:0:0");
  
      xbt_cfg_register(&_sg_cfg_set, "smpi/ois",
                       "Small messages timings (MPI_Isend minimum time for small messages)",
-                      xbt_cfgelm_string, NULL, 1, 1, NULL,
-                      NULL);
+                      xbt_cfgelm_string, 1, 1, NULL, NULL);
      xbt_cfg_setdefault_string(_sg_cfg_set, "smpi/ois", "1:0:0:0:0");
  
      xbt_cfg_register(&_sg_cfg_set, "smpi/or",
                       "Small messages timings (MPI_Recv minimum time for small messages)",
-                      xbt_cfgelm_string, NULL, 1, 1, NULL,
-                      NULL);
+                      xbt_cfgelm_string, 1, 1, NULL, NULL);
      xbt_cfg_setdefault_string(_sg_cfg_set, "smpi/or", "1:0:0:0:0");
-     double default_iprobe_time = 1e-4;
      xbt_cfg_register(&_sg_cfg_set, "smpi/iprobe",
                       "Minimum time to inject inside a call to MPI_Iprobe",
-                      xbt_cfgelm_double, &default_iprobe_time, 1, 1, NULL,
-                      NULL);
-     default_value = xbt_strdup("default");
+                      xbt_cfgelm_double, 1, 1, NULL, NULL);
+     xbt_cfg_setdefault_double(_sg_cfg_set, "smpi/iprobe", 1e-4);
      xbt_cfg_register(&_sg_cfg_set, "smpi/coll_selector",
-                    "Which collective selector to use",
-                    xbt_cfgelm_string, &default_value, 1, 1, NULL,
-                    NULL);
-                    
-               xbt_cfg_register(&_sg_cfg_set, "smpi/gather",
-                    "Which collective to use for gather",
-                    xbt_cfgelm_string, NULL, 1, 1, &_sg_cfg_cb__coll_gather,
-                    NULL);
-                    
+                      "Which collective selector to use",
+                      xbt_cfgelm_string, 1, 1, NULL, NULL);
+     xbt_cfg_setdefault_string(_sg_cfg_set, "smpi/coll_selector", "default");
+     xbt_cfg_register(&_sg_cfg_set, "smpi/gather",
+                      "Which collective to use for gather",
+                      xbt_cfgelm_string, 1, 1, &_sg_cfg_cb__coll_gather, NULL);
      xbt_cfg_register(&_sg_cfg_set, "smpi/allgather",
-                    "Which collective to use for allgather",
-                    xbt_cfgelm_string, NULL, 1, 1, &_sg_cfg_cb__coll_allgather,
-                    NULL);
+                      "Which collective to use for allgather",
+                      xbt_cfgelm_string, 1, 1, &_sg_cfg_cb__coll_allgather, NULL);
  
      xbt_cfg_register(&_sg_cfg_set, "smpi/barrier",
-                    "Which collective to use for barrier",
-                    xbt_cfgelm_string, NULL, 1, 1, &_sg_cfg_cb__coll_barrier,
-                    NULL);
+                      "Which collective to use for barrier",
+                      xbt_cfgelm_string, 1, 1, &_sg_cfg_cb__coll_barrier, NULL);
  
      xbt_cfg_register(&_sg_cfg_set, "smpi/reduce_scatter",
-                    "Which collective to use for reduce_scatter",
-                    xbt_cfgelm_string, NULL, 1, 1, &_sg_cfg_cb__coll_reduce_scatter,
-                    NULL);
+                      "Which collective to use for reduce_scatter",
+                      xbt_cfgelm_string, 1, 1, &_sg_cfg_cb__coll_reduce_scatter, NULL);
  
      xbt_cfg_register(&_sg_cfg_set, "smpi/scatter",
-                    "Which collective to use for scatter",
-                    xbt_cfgelm_string, NULL, 1, 1, &_sg_cfg_cb__coll_scatter,
-                    NULL);
+                      "Which collective to use for scatter",
+                      xbt_cfgelm_string, 1, 1, &_sg_cfg_cb__coll_scatter, NULL);
  
      xbt_cfg_register(&_sg_cfg_set, "smpi/allgatherv",
-                    "Which collective to use for allgatherv",
-                    xbt_cfgelm_string, NULL, 1, 1, &_sg_cfg_cb__coll_allgatherv,
-                    NULL);
+                      "Which collective to use for allgatherv",
+                      xbt_cfgelm_string, 1, 1, &_sg_cfg_cb__coll_allgatherv, NULL);
  
      xbt_cfg_register(&_sg_cfg_set, "smpi/allreduce",
-                    "Which collective to use for allreduce",
-                    xbt_cfgelm_string, NULL, 1, 1, &_sg_cfg_cb__coll_allreduce,
-                    NULL);
+                      "Which collective to use for allreduce",
+                      xbt_cfgelm_string, 1, 1, &_sg_cfg_cb__coll_allreduce, NULL);
  
      xbt_cfg_register(&_sg_cfg_set, "smpi/alltoall",
-                    "Which collective to use for alltoall",
-                    xbt_cfgelm_string, NULL, 1, 1, &_sg_cfg_cb__coll_alltoall,
-                    NULL);
+                      "Which collective to use for alltoall",
+                      xbt_cfgelm_string, 1, 1, &_sg_cfg_cb__coll_alltoall, NULL);
  
      xbt_cfg_register(&_sg_cfg_set, "smpi/alltoallv",
-                    "Which collective to use for alltoallv",
-                    xbt_cfgelm_string, NULL, 1, 1, &_sg_cfg_cb__coll_alltoallv,
-                    NULL);
+                      "Which collective to use for alltoallv",
+                      xbt_cfgelm_string, 1, 1, &_sg_cfg_cb__coll_alltoallv, NULL);
  
      xbt_cfg_register(&_sg_cfg_set, "smpi/bcast",
-                    "Which collective to use for bcast",
-                    xbt_cfgelm_string, NULL, 1, 1, &_sg_cfg_cb__coll_bcast,
-                    NULL);
+                      "Which collective to use for bcast",
+                      xbt_cfgelm_string, 1, 1, &_sg_cfg_cb__coll_bcast, NULL);
  
      xbt_cfg_register(&_sg_cfg_set, "smpi/reduce",
-                    "Which collective to use for reduce",
-                    xbt_cfgelm_string, NULL, 1, 1, &_sg_cfg_cb__coll_reduce,
-                    NULL);
+                      "Which collective to use for reduce",
+                      xbt_cfgelm_string, 1, 1, &_sg_cfg_cb__coll_reduce, NULL);
  #endif // HAVE_SMPI
  
+     xbt_cfg_register(&_sg_cfg_set, "clean_atexit",
+                      "\"yes\" or \"no\". \"yes\" enables all the cleanups of SimGrid (XBT,SIMIX,MSG) to be registered with atexit. \"no\" may be useful if your code segfaults when calling the exit function.",
+                      xbt_cfgelm_boolean, 1, 1, _sg_cfg_cb_clean_atexit, NULL);
+     xbt_cfg_setdefault_boolean(_sg_cfg_set, "clean_atexit", "yes");
      if (!surf_path) {
-       /* retrieves the current directory of the        current process */
+       /* retrieves the current directory of the current process */
        const char *initial_path = __surf_get_initial_path();
        xbt_assert((initial_path),
                    "__surf_get_initial_path() failed! Can't resolves current Windows directory");
        xbt_cfg_setdefault_string(_sg_cfg_set, "path", initial_path);
      }
  
-     _sg_init_status = 1;
+     _sg_cfg_init_status = 1;
  
      sg_config_cmd_line(argc, argv);
  
    } else {
      XBT_WARN("Call to sg_config_init() after initialization ignored");
    }
+   xbt_free(description);
  }
  
  void sg_config_finalize(void)
  {
-   if (!_sg_init_status)
+   if (!_sg_cfg_init_status)
      return;                     /* Not initialized yet. Nothing to do */
  
    xbt_cfg_free(&_sg_cfg_set);
-   _sg_init_status = 0;
+   _sg_cfg_init_status = 0;
  }
  
  /* Pick the right models for CPU, net and workstation, and call their model_init_preparse */
  void surf_config_models_setup()
  {
-   char *workstation_model_name;
+   const char *workstation_model_name;
    int workstation_id = -1;
    char *network_model_name = NULL;
    char *cpu_model_name = NULL;
     * the right net/cpu models.
     */
  
-   if((!xbt_cfg_is_default_value(_sg_cfg_set, "network/model") ||
-     !xbt_cfg_is_default_value(_sg_cfg_set, "cpu/model")) &&
-     xbt_cfg_is_default_value(_sg_cfg_set, "workstation/model"))
-   {
-       const char *val = "compound";
-       XBT_INFO
-           ("Switching workstation model to compound since you changed the network and/or cpu model(s)");
-       xbt_cfg_set_string(_sg_cfg_set, "workstation/model", val);
-       workstation_model_name = (char *) "compound";
+   if ((!xbt_cfg_is_default_value(_sg_cfg_set, "network/model") ||
+        !xbt_cfg_is_default_value(_sg_cfg_set, "cpu/model")) &&
+       xbt_cfg_is_default_value(_sg_cfg_set, "workstation/model")) {
+     XBT_INFO("Switching workstation model to compound since you changed the network and/or cpu model(s)");
+     workstation_model_name = "compound";
+     xbt_cfg_set_string(_sg_cfg_set, "workstation/model", workstation_model_name);
    }
  
    XBT_DEBUG("Workstation model: %s", workstation_model_name);
    storage_id = find_model_description(surf_storage_model_description, storage_model_name);
    surf_storage_model_description[storage_id].model_init_preparse();
  
 -  /* ********************************************************************* */
 -  /* TUTORIAL: New model                                                   */
 -  int new_model_id = -1;
 -  char *new_model_name = NULL;
 -  new_model_name = xbt_cfg_get_string(_sg_cfg_set, "new_model/model");
 -  XBT_DEBUG("Call new model_init");
 -  new_model_id = find_model_description(surf_new_model_description, new_model_name);
 -  surf_new_model_description[new_model_id].model_init_preparse();
 -  /* ********************************************************************* */
  }
  
  int sg_cfg_get_int(const char* name)
  {
-       return xbt_cfg_get_int(_sg_cfg_set,name);
+   return xbt_cfg_get_int(_sg_cfg_set,name);
  }
  double sg_cfg_get_double(const char* name)
  {
-       return xbt_cfg_get_double(_sg_cfg_set,name);
+   return xbt_cfg_get_double(_sg_cfg_set,name);
  }
  char* sg_cfg_get_string(const char* name)
  {
-       return xbt_cfg_get_string(_sg_cfg_set,name);
+   return xbt_cfg_get_string(_sg_cfg_set,name);
  }
  int sg_cfg_get_boolean(const char* name)
  {
-       return xbt_cfg_get_boolean(_sg_cfg_set,name);
+   return xbt_cfg_get_boolean(_sg_cfg_set,name);
  }
  void sg_cfg_get_peer(const char *name, char **peer, int *port)
  {
-       xbt_cfg_get_peer(_sg_cfg_set,name, peer, port);
+   xbt_cfg_get_peer(_sg_cfg_set,name, peer, port);
  }
  xbt_dynar_t sg_cfg_get_dynar(const char* name)
  {
-       return xbt_cfg_get_dynar(_sg_cfg_set,name);
+   return xbt_cfg_get_dynar(_sg_cfg_set,name);
  }
diff --combined src/simix/smx_global.c
@@@ -1,4 -1,5 +1,5 @@@
- /* Copyright (c) 2007-2012. The SimGrid Team. All rights reserved.          */
+ /* Copyright (c) 2007-2013. 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. */
@@@ -10,6 -11,7 +11,7 @@@
  #include "xbt/str.h"
  #include "xbt/ex.h"             /* ex_backtrace_display */
  #include "mc/mc.h"
+ #include "simgrid/sg_config.h"
  
  XBT_LOG_NEW_CATEGORY(simix, "All SIMIX categories");
  XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_kernel, simix,
@@@ -107,8 -109,13 +109,13 @@@ void SIMIX_global_init(int *argc, char 
    }
  
    SIMIX_HOST_LEVEL = xbt_lib_add_level(host_lib,SIMIX_host_destroy);
+   SIMIX_STORAGE_LEVEL = xbt_lib_add_level(storage_lib, SIMIX_storage_destroy);
  
-   atexit(SIMIX_clean);
+   if (sg_cfg_get_boolean("clean_atexit"))
+     atexit(SIMIX_clean);
+   if (_sg_cfg_exit_asap)
+     exit(0);
  }
  
  /**
@@@ -157,7 -164,7 +164,7 @@@ static void SIMIX_clean(void
  
  #ifdef TIME_BENCH_AMDAHL
    xbt_os_cputimer_stop(simix_global->timer_seq);
-   XBT_INFO("Amdhal timing informations. Sequential time: %lf; Parallel time: %lf",
+   XBT_INFO("Amdahl timing informations. Sequential time: %f; Parallel time: %f",
             xbt_os_timer_elapsed(simix_global->timer_seq),
             xbt_os_timer_elapsed(simix_global->timer_par));
    xbt_os_timer_free(simix_global->timer_seq);
@@@ -317,17 -324,26 +324,27 @@@ void SIMIX_run(void
           ((void (*)(void*))timer->func)(timer->args);
         xbt_free(timer);
      }
 +
      /* Wake up all processes waiting for a Surf action to finish */
      xbt_dynar_foreach(model_list, iter, model) {
 -      set = model->states.failed_action_set;
 +      set = surf_model_failed_action_set(model);
        while ((action = xbt_swag_extract(set)))
 -        SIMIX_simcall_post((smx_action_t) action->data);
 -      set = model->states.done_action_set;
 +        SIMIX_simcall_post((smx_action_t) surf_action_get_data(action));
 +      set = surf_model_done_action_set(model);
        while ((action = xbt_swag_extract(set)))
 -        SIMIX_simcall_post((smx_action_t) action->data);
 +        SIMIX_simcall_post((smx_action_t) surf_action_get_data(action));
      }
  
+     /* Autorestart all process */
+     if(host_that_restart) {
+       char *hostname = NULL;
+       xbt_dynar_foreach(host_that_restart,iter,hostname) {
+         XBT_INFO("Restart processes on host: %s",hostname);
+         SIMIX_host_autorestart(SIMIX_host_get_by_name(hostname));
+       }
+       xbt_dynar_reset(host_that_restart);
+     }
      /* Clean processes to destroy */
      SIMIX_process_empty_trash();
  
      TRACE_end();
  #endif
  
-     XBT_WARN("Oops ! Deadlock or code not perfectly clean.");
+     XBT_CRITICAL("Oops ! Deadlock or code not perfectly clean.");
      SIMIX_display_process_status();
      xbt_abort();
    }
diff --combined src/simix/smx_host.c
@@@ -1,4 -1,4 +1,4 @@@
- /* Copyright (c) 2007-2012. The SimGrid Team.
+ /* Copyright (c) 2007-2013. The SimGrid Team.
   * All rights reserved.                                                     */
  
  /* This program is free software; you can redistribute it and/or modify it
@@@ -34,8 -34,8 +34,8 @@@ smx_host_t SIMIX_host_create(const cha
  
    /* Update global variables */
    xbt_lib_set(host_lib,name,SIMIX_HOST_LEVEL,smx_host);
-   
-   return xbt_lib_get_elm_or_null(host_lib, name);
+   return xbt_lib_get_or_null(host_lib, name, SIMIX_HOST_LEVEL);
  }
  
  /**
@@@ -135,7 -135,7 +135,7 @@@ xbt_dict_t SIMIX_pre_host_get_propertie
  xbt_dict_t SIMIX_host_get_properties(smx_host_t host){
    xbt_assert((host != NULL), "Invalid parameters (simix host is NULL)");
  
 -  return surf_workstation_model->extension.workstation.get_properties(host);
 +  return surf_resource_get_properties(surf_workstation_resource_priv(host));
  }
  
  double SIMIX_pre_host_get_speed(smx_simcall_t simcall, smx_host_t host){
  }
  double SIMIX_host_get_speed(smx_host_t host){
    xbt_assert((host != NULL), "Invalid parameters (simix host is NULL)");
 -
 -  return surf_workstation_model->extension.workstation.
 -      get_speed(host, 1.0);
 +  return surf_workstation_get_speed(host, 1.0);
  }
  
  int SIMIX_pre_host_get_core(smx_simcall_t simcall, smx_host_t host){
  int SIMIX_host_get_core(smx_host_t host){
    xbt_assert((host != NULL), "Invalid parameters (simix host is NULL)");
  
 -  return surf_workstation_model->extension.workstation.
 -      get_core(host);
 +  return surf_workstation_get_core(host);
  }
  
+ xbt_swag_t SIMIX_pre_host_get_process_list(smx_simcall_t simcall, smx_host_t host){
+   return SIMIX_host_get_process_list(host);
+ }
+ xbt_swag_t SIMIX_host_get_process_list(smx_host_t host){
+   xbt_assert((host != NULL), "Invalid parameters (simix host is NULL)");
+   smx_host_priv_t host_priv = SIMIX_host_priv(host);
+   return host_priv->process_list;
+ }
  
  
  double SIMIX_pre_host_get_available_speed(smx_simcall_t simcall, smx_host_t host){
  double SIMIX_host_get_available_speed(smx_host_t host){
    xbt_assert((host != NULL), "Invalid parameters (simix host is NULL)");
  
 -  return surf_workstation_model->extension.workstation.
 -      get_available_speed(host);
 +  return surf_workstation_get_available_speed(host);
  }
  
 -        return surf_workstation_model->extension.workstation.
 -                    get_current_power_peak(host);
+ double SIMIX_pre_host_get_current_power_peak(smx_simcall_t simcall, smx_host_t host){
+   return SIMIX_host_get_current_power_peak(host);
+ }
+ double SIMIX_host_get_current_power_peak(smx_host_t host) {
+         xbt_assert((host != NULL), "Invalid parameters (simix host is NULL)");
 -        return surf_workstation_model->extension.workstation.
 -            get_power_peak_at(host, pstate_index);
++        return surf_workstation_get_current_power_peak(host);
+ }
+ double SIMIX_pre_host_get_power_peak_at(smx_simcall_t simcall, smx_host_t host, int pstate_index){
+   return SIMIX_host_get_power_peak_at(host, pstate_index);
+ }
+ double SIMIX_host_get_power_peak_at(smx_host_t host, int pstate_index) {
+         xbt_assert((host != NULL), "Invalid parameters (simix host is NULL)");
 -        return surf_workstation_model->extension.workstation.
 -            get_nb_pstates(host);
++        return surf_workstation_get_power_peak_at(host, pstate_index);
+ }
+ int SIMIX_pre_host_get_nb_pstates(smx_simcall_t simcall, smx_host_t host){
+   return SIMIX_host_get_nb_pstates(host);
+ }
+ int SIMIX_host_get_nb_pstates(smx_host_t host) {
+         xbt_assert((host != NULL), "Invalid parameters (simix host is NULL)");
 -        surf_workstation_model->extension.workstation.
 -            set_power_peak_at(host, pstate_index);
++        return surf_workstation_get_nb_pstates(host);
+ }
+ void SIMIX_pre_host_set_power_peak_at(smx_simcall_t simcall, smx_host_t host, int pstate_index){
+   SIMIX_host_set_power_peak_at(host, pstate_index);
+ }
+ void SIMIX_host_set_power_peak_at(smx_host_t host, int pstate_index) {
+         xbt_assert((host != NULL), "Invalid parameters (simix host is NULL)");
 -        return surf_workstation_model->extension.workstation.
 -                    get_consumed_energy(host);
++        surf_workstation_set_power_peak_at(host, pstate_index);
+ }
+ double SIMIX_pre_host_get_consumed_energy(smx_simcall_t simcall, smx_host_t host){
+   return SIMIX_host_get_consumed_energy(host);
+ }
+ double SIMIX_host_get_consumed_energy(smx_host_t host) {
+         xbt_assert((host != NULL), "Invalid parameters (simix host is NULL)");
++        return surf_workstation_get_consumed_energy(host);
+ }
  int SIMIX_pre_host_get_state(smx_simcall_t simcall, smx_host_t host){
    return SIMIX_host_get_state(host);
  }
  int SIMIX_host_get_state(smx_host_t host){
    xbt_assert((host != NULL), "Invalid parameters (simix host is NULL)");
  
 -  return surf_workstation_model->extension.workstation.
 -      get_state(host);
 +  return surf_resource_get_state(surf_workstation_resource_priv(host));
  }
  
  void* SIMIX_pre_host_self_get_data(smx_simcall_t simcall){
@@@ -198,10 -262,14 +252,14 @@@ void* SIMIX_host_get_data(smx_host_t ho
  
    return SIMIX_host_priv(host)->data;
  }
- void _SIMIX_host_free_process_arg(void *);
- void _SIMIX_host_free_process_arg(void *data)
static void _SIMIX_host_free_process_arg(void *data)
  {
    smx_process_arg_t arg = *(void**)data;
+   int i;
+   for (i = 0; i < arg->argc; i++)
+     xbt_free(arg->argv[i]);
+   xbt_free(arg->argv);
    xbt_free(arg->name);
    xbt_free(arg);
  }
@@@ -247,7 -315,7 +305,7 @@@ void SIMIX_host_add_auto_restart_proces
    if( SIMIX_host_get_state(host) == SURF_RESOURCE_OFF
        && !xbt_dict_get_or_null(watched_hosts_lib,sg_host_name(host))){
      xbt_dict_set(watched_hosts_lib,sg_host_name(host),host,NULL);
-     XBT_DEBUG("Have push host %s to watched_hosts_lib because state == SURF_RESOURCE_OFF",sg_host_name(host));
+     XBT_DEBUG("Have pushed host %s to watched_hosts_lib because state == SURF_RESOURCE_OFF",sg_host_name(host));
    }
    xbt_dynar_push_as(SIMIX_host_priv(host)->auto_restart_processes,smx_process_arg_t,arg);
  }
@@@ -258,7 -326,11 +316,11 @@@ void SIMIX_host_restart_processes(smx_h
  {
    unsigned int cpt;
    smx_process_arg_t arg;
-   xbt_dynar_foreach(SIMIX_host_priv(host)->auto_restart_processes,cpt,arg) {
+   xbt_dynar_t process_list = SIMIX_host_priv(host)->auto_restart_processes;
+   if (!process_list)
+     return;
+   xbt_dynar_foreach (process_list, cpt, arg) {
  
      smx_process_t process;
  
                                              arg->argv,
                                              arg->properties,
                                              arg->auto_restart);
-     }
-     else {
+     } else {
        simcall_process_create(&process,
-                                             arg->argv[0],
-                                             arg->code,
-                                             NULL,
-                                             arg->hostname,
-                                             arg->kill_time,
-                                             arg->argc,
-                                             arg->argv,
-                                             arg->properties,
-                                             arg->auto_restart);
+                              arg->argv[0],
+                              arg->code,
+                              NULL,
+                              arg->hostname,
+                              arg->kill_time,
+                              arg->argc,
+                              arg->argv,
+                              arg->properties,
+                              arg->auto_restart);
  
      }
+     /* arg->argv is used by the process created above.  Hide it to
+      * _SIMIX_host_free_process_arg() which is called by xbt_dynar_reset()
+      * below. */
+     arg->argc = 0;
+     arg->argv = NULL;
    }
-   xbt_dynar_reset(SIMIX_host_priv(host)->auto_restart_processes);
+   xbt_dynar_reset(process_list);
  }
  
  void SIMIX_host_autorestart(smx_host_t host)
@@@ -331,9 -407,10 +397,9 @@@ smx_action_t SIMIX_host_execute(const c
    /* set surf's action */
    if (!MC_is_active()) {
      action->execution.surf_exec =
 -      surf_workstation_model->extension.workstation.execute(host,
 -    computation_amount);
 -    surf_workstation_model->action_data_set(action->execution.surf_exec, action);
 -    surf_workstation_model->set_priority(action->execution.surf_exec, priority);
 +      surf_workstation_execute(host, computation_amount);
 +    surf_action_set_data(action->execution.surf_exec, action);
 +    surf_action_set_priority(action->execution.surf_exec, priority);
    }
  
    XBT_DEBUG("Create execute action %p", action);
@@@ -370,15 -447,16 +436,15 @@@ smx_action_t SIMIX_host_parallel_execut
    /* set surf's action */
    workstation_list = xbt_new0(void *, host_nb);
    for (i = 0; i < host_nb; i++)
 -    workstation_list[i] = host_list[i];
 +    workstation_list[i] = surf_workstation_resource_priv(host_list[i]);
  
    /* set surf's action */
    if (!MC_is_active()) {
      action->execution.surf_exec =
 -      surf_workstation_model->extension.workstation.
 -      execute_parallel_task(host_nb, workstation_list, computation_amount,
 -                      communication_amount, rate);
 +      surf_workstation_model_execute_parallel_task((surf_workstation_model_t)surf_workstation_model,
 +                host_nb, workstation_list, computation_amount, communication_amount, rate);
  
 -    surf_workstation_model->action_data_set(action->execution.surf_exec, action);
 +    surf_action_set_data(action->execution.surf_exec, action);
    }
    XBT_DEBUG("Create parallel execute action %p", action);
  
@@@ -392,7 -470,7 +458,7 @@@ void SIMIX_host_execution_destroy(smx_a
    XBT_DEBUG("Destroy action %p", action);
  
    if (action->execution.surf_exec) {
 -    surf_workstation_model->action_unref(action->execution.surf_exec);
 +    surf_action_unref(action->execution.surf_exec);
      action->execution.surf_exec = NULL;
    }
    xbt_free(action->name);
@@@ -406,7 -484,7 +472,7 @@@ void SIMIX_host_execution_cancel(smx_ac
    XBT_DEBUG("Cancel action %p", action);
  
    if (action->execution.surf_exec)
 -    surf_workstation_model->action_cancel(action->execution.surf_exec);
 +    surf_action_cancel(action->execution.surf_exec);
  }
  
  double SIMIX_pre_host_execution_get_remains(smx_simcall_t simcall, smx_action_t action){
@@@ -416,7 -494,7 +482,7 @@@ double SIMIX_host_execution_get_remains
    double result = 0.0;
  
    if (action->state == SIMIX_RUNNING)
 -    result = surf_workstation_model->get_remains(action->execution.surf_exec);
 +    result = surf_action_get_remains(action->execution.surf_exec);
  
    return result;
  }
@@@ -434,7 -512,7 +500,7 @@@ void SIMIX_pre_host_execution_set_prior
  }
  void SIMIX_host_execution_set_priority(smx_action_t action, double priority){
    if(action->execution.surf_exec)
 -    surf_workstation_model->set_priority(action->execution.surf_exec, priority);
 +      surf_action_set_priority(action->execution.surf_exec, priority);
  }
  
  void SIMIX_pre_host_execution_wait(smx_simcall_t simcall, smx_action_t action){
  void SIMIX_host_execution_suspend(smx_action_t action)
  {
    if(action->execution.surf_exec)
 -    surf_workstation_model->suspend(action->execution.surf_exec);
 +    surf_action_suspend(action->execution.surf_exec);
  }
  
  void SIMIX_host_execution_resume(smx_action_t action)
  {
    if(action->execution.surf_exec)
 -    surf_workstation_model->resume(action->execution.surf_exec);
 +    surf_action_resume(action->execution.surf_exec);
  }
  
  void SIMIX_execution_finish(smx_action_t action)
        case SIMIX_FAILED:
          XBT_DEBUG("SIMIX_execution_finished: host '%s' failed", sg_host_name(simcall->issuer->smx_host));
          simcall->issuer->context->iwannadie = 1;
-         //SMX_EXCEPTION(simcall->issuer, host_error, 0, "Host failed");
+         SMX_EXCEPTION(simcall->issuer, host_error, 0, "Host failed");
          break;
  
        case SIMIX_CANCELED:
              (int)action->state);
      }
      /* check if the host is down */
 -    if (surf_workstation_model->extension.
 -        workstation.get_state(simcall->issuer->smx_host) != SURF_RESOURCE_ON) {
 +
 +    if (surf_resource_get_state(surf_workstation_resource_priv(simcall->issuer->smx_host)) != SURF_RESOURCE_ON) {
        simcall->issuer->context->iwannadie = 1;
      }
  
@@@ -517,11 -595,11 +583,11 @@@ void SIMIX_post_host_execute(smx_action
  {
    if (action->type == SIMIX_ACTION_EXECUTE && /* FIMXE: handle resource failure
                                                 * for parallel tasks too */
 -      surf_workstation_model->extension.workstation.get_state(action->execution.host) == SURF_RESOURCE_OFF) {
 +      surf_resource_get_state(surf_workstation_resource_priv(action->execution.host)) == SURF_RESOURCE_OFF) {
      /* If the host running the action failed, notice it so that the asking
       * process can be killed if it runs on that host itself */
      action->state = SIMIX_FAILED;
 -  } else if (surf_workstation_model->action_state_get(action->execution.surf_exec) == SURF_ACTION_FAILED) {
 +  } else if (surf_action_get_state(action->execution.surf_exec) == SURF_ACTION_FAILED) {
      /* If the host running the action didn't fail, then the action was
       * canceled */
      action->state = SIMIX_CANCELED;
    }
  
    if (action->execution.surf_exec) {
 -    surf_workstation_model->action_unref(action->execution.surf_exec);
 +    surf_action_unref(action->execution.surf_exec);
      action->execution.surf_exec = NULL;
    }
  
@@@ -550,10 -628,18 +616,18 @@@ void SIMIX_set_category(smx_action_t ac
  {
    if (action->state != SIMIX_RUNNING) return;
    if (action->type == SIMIX_ACTION_EXECUTE){
 -    surf_workstation_model->set_category(action->execution.surf_exec, category);
 +    surf_action_set_category(action->execution.surf_exec, category);
    }else if (action->type == SIMIX_ACTION_COMMUNICATE){
 -    surf_workstation_model->set_category(action->comm.surf_comm, category);
 +    surf_action_set_category(action->comm.surf_comm, category);
    }
  }
  #endif
  
 -  return surf_workstation_model->extension.workstation.get_storage_list(host);
+ xbt_dict_t SIMIX_pre_host_get_storage_list(smx_simcall_t simcall, smx_host_t host){
+   return SIMIX_host_get_storage_list(host);
+ }
+ xbt_dict_t SIMIX_host_get_storage_list(smx_host_t host){
+   xbt_assert((host != NULL), "Invalid parameters (simix host is NULL)");
++  return surf_workstation_get_storage_list(host);
+ }
@@@ -1,4 -1,4 +1,4 @@@
- /* Copyright (c) 2007, 2008, 2009, 2010. The SimGrid Team.
+ /* Copyright (c) 2007-2010, 2012-2013. The SimGrid Team.
   * All rights reserved.                                                     */
  
  /* This program is free software; you can redistribute it and/or modify it
@@@ -18,12 -18,10 +18,12 @@@ typedef struct s_smx_host_priv 
  } s_smx_host_priv_t;
  
  static inline smx_host_priv_t SIMIX_host_priv(smx_host_t host){
 -  return xbt_lib_get_level(host, SIMIX_HOST_LEVEL);
 +  return (smx_host_priv_t) xbt_lib_get_level(host, SIMIX_HOST_LEVEL);
  }
  
 -
 +#ifdef __cplusplus
 +extern "C" {
 +#endif
  smx_host_t SIMIX_host_create(const char *name, void *workstation, void *data);
  void SIMIX_host_destroy(void *host);
  
@@@ -41,9 -39,15 +41,15 @@@ void SIMIX_host_restart_processes(smx_h
  void SIMIX_host_autorestart(smx_host_t host);
  xbt_dict_t SIMIX_host_get_properties(smx_host_t host);
  int SIMIX_host_get_core(smx_host_t host);
+ xbt_swag_t SIMIX_host_get_process_list(smx_host_t host);
  double SIMIX_host_get_speed(smx_host_t host);
  double SIMIX_host_get_available_speed(smx_host_t host);
  int SIMIX_host_get_state(smx_host_t host);
+ double SIMIX_host_get_current_power_peak(smx_host_t host);
+ double SIMIX_host_get_power_peak_at(smx_host_t host, int pstate_index);
+ int SIMIX_host_get_nb_pstates(smx_host_t host);
+ double SIMIX_host_get_consumed_energy(smx_host_t host);
+ void SIMIX_host_set_power_peak_at(smx_host_t host, int pstate_index);
  smx_action_t SIMIX_host_execute(const char *name,
      smx_host_t host, double computation_amount, double priority);
  smx_action_t SIMIX_host_parallel_execute(const char *name,
@@@ -56,6 -60,7 +62,7 @@@ double SIMIX_host_execution_get_remains
  e_smx_state_t SIMIX_host_execution_get_state(smx_action_t action);
  void SIMIX_host_execution_set_priority(smx_action_t action, double priority);
  void SIMIX_pre_host_execution_wait(smx_simcall_t simcall, smx_action_t action);
+ xbt_dict_t SIMIX_host_get_storage_list(smx_host_t host);
  
  // pre prototypes
  smx_host_t SIMIX_pre_host_get_by_name(smx_simcall_t, const char*);
@@@ -63,9 -68,15 +70,15 @@@ const char* SIMIX_pre_host_self_get_nam
  const char* SIMIX_pre_host_get_name(smx_simcall_t, smx_host_t);
  xbt_dict_t SIMIX_pre_host_get_properties(smx_simcall_t, smx_host_t);
  int SIMIX_pre_host_get_core(smx_simcall_t, smx_host_t);
+ xbt_swag_t SIMIX_pre_host_get_process_list(smx_simcall_t, smx_host_t host);
  double SIMIX_pre_host_get_speed(smx_simcall_t, smx_host_t);
  double SIMIX_pre_host_get_available_speed(smx_simcall_t, smx_host_t);
  int SIMIX_pre_host_get_state(smx_simcall_t, smx_host_t);
+ double SIMIX_pre_host_get_current_power_peak(smx_simcall_t, smx_host_t);
+ double SIMIX_pre_host_get_power_peak_at(smx_simcall_t, smx_host_t host, int pstate_index);
+ int SIMIX_pre_host_get_nb_pstates(smx_simcall_t, smx_host_t host);
+ void SIMIX_pre_host_set_power_peak_at(smx_simcall_t, smx_host_t host, int pstate_index);
+ double SIMIX_pre_host_get_consumed_energy(smx_simcall_t, smx_host_t);
  void* SIMIX_pre_host_self_get_data(smx_simcall_t);
  void* SIMIX_pre_host_get_data(smx_simcall_t, smx_host_t);
  void SIMIX_pre_host_set_data(smx_simcall_t, smx_host_t, void*);
@@@ -82,16 -93,12 +95,16 @@@ void SIMIX_host_execution_suspend(smx_a
  void SIMIX_host_execution_resume(smx_action_t action);
  
  void SIMIX_post_host_execute(smx_action_t action);
+ xbt_dict_t SIMIX_pre_host_get_storage_list(smx_simcall_t, smx_host_t);
  #ifdef HAVE_TRACING
  void SIMIX_pre_set_category(smx_simcall_t simcall, smx_action_t action,
                            const char *category);
  void SIMIX_set_category(smx_action_t action, const char *category);
  #endif
  
 +#ifdef __cplusplus
 +}
 +#endif
 +
  #endif
  
diff --combined src/simix/smx_io.c
@@@ -1,11 -1,11 +1,11 @@@
- /* Copyright (c) 2007, 2008, 2009, 2010. The SimGrid Team.
+ /* Copyright (c) 2007-2010, 2012-2013. 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. */
  
  #include "smx_private.h"
--#include "surf/storage_private.h"
++//#include "surf/storage_private.h"
  #include "xbt/sysdep.h"
  #include "xbt/log.h"
  #include "xbt/dict.h"
@@@ -15,23 -15,77 +15,76 @@@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_i
                                  "Logging specific to SIMIX (io)");
  
  
+ /**
+  * \brief Internal function to create a SIMIX storage.
+  * \param name name of the storage to create
+  * \param storage the SURF storage to encapsulate
+  * \param data some user data (may be NULL)
+  */
+ smx_storage_t SIMIX_storage_create(const char *name, void *storage, void *data)
+ {
+   smx_storage_priv_t smx_storage = xbt_new0(s_smx_storage_priv_t, 1);
+   smx_storage->data = data;
+   /* Update global variables */
+   xbt_lib_set(storage_lib,name,SIMIX_STORAGE_LEVEL,smx_storage);
+   return xbt_lib_get_or_null(storage_lib, name, SIMIX_STORAGE_LEVEL);
+ }
+ /**
+  * \brief Internal function to destroy a SIMIX storage.
+  *
+  * \param s the host to destroy (a smx_storage_t)
+  */
+ void SIMIX_storage_destroy(void *s)
+ {
+   smx_storage_priv_t storage = (smx_storage_priv_t) s;
+   xbt_assert((storage != NULL), "Invalid parameters");
+   if (storage->data)
+     free(storage->data);
+   /* Clean storage structure */
+   free(storage);
+ }
+ void* SIMIX_pre_file_get_data(smx_simcall_t simcall,smx_file_t fd){
+   return SIMIX_file_get_data(fd);
+ }
+ void* SIMIX_file_get_data(smx_file_t fd){
+   xbt_assert((fd != NULL), "Invalid parameters (simix file is NULL)");
+   return fd->data;
+ }
+ void SIMIX_pre_file_set_data(smx_simcall_t simcall, smx_file_t fd, void *data) {
+   SIMIX_file_set_data(fd, data);
+ }
+ void SIMIX_file_set_data(smx_file_t fd, void *data){
+   xbt_assert((fd != NULL), "Invalid parameter");
+   fd->data = data;
+ }
  //SIMIX FILE READ
- void SIMIX_pre_file_read(smx_simcall_t simcall, void *ptr, size_t size,
-                       smx_file_t fd)
+ void SIMIX_pre_file_read(smx_simcall_t simcall, smx_file_t fd, sg_storage_size_t size)
  {
-   smx_action_t action = SIMIX_file_read(simcall->issuer, ptr, size, fd);
+   smx_action_t action = SIMIX_file_read(simcall->issuer, fd, size);
    xbt_fifo_push(action->simcalls, simcall);
    simcall->issuer->waiting_action = action;
  }
  
- smx_action_t SIMIX_file_read(smx_process_t process, void* ptr, size_t size,
-                              smx_file_t fd)
+ smx_action_t SIMIX_file_read(smx_process_t process, smx_file_t fd, sg_storage_size_t size)
  {
    smx_action_t action;
    smx_host_t host = process->smx_host;
  
    /* check if the host is active */
 -  if (surf_workstation_model->extension.
 -      workstation.get_state(host) != SURF_RESOURCE_ON) {
 +  if (surf_resource_get_state(surf_workstation_resource_priv(host)) != SURF_RESOURCE_ON) {
      THROWF(host_error, 0, "Host %s failed, you cannot call this function",
             sg_host_name(host));
    }
  #endif
  
    action->io.host = host;
-   action->io.surf_io = surf_workstation_read(host, ptr, size, fd->surf_file);
 -  action->io.surf_io =
 -      surf_workstation_model->extension.workstation.read(host, fd->surf_file, size);
++  action->io.surf_io = surf_workstation_read(host, fd->surf_file, size);
  
 -  surf_workstation_model->action_data_set(action->io.surf_io, action);
 +  surf_action_set_data(action->io.surf_io, action);
    XBT_DEBUG("Create io action %p", action);
  
    return action;
  }
  
  //SIMIX FILE WRITE
- void SIMIX_pre_file_write(smx_simcall_t simcall, const void *ptr, size_t size,
-                         smx_file_t fd)
+ void SIMIX_pre_file_write(smx_simcall_t simcall, smx_file_t fd, sg_storage_size_t size)
  {
-   smx_action_t action = SIMIX_file_write(simcall->issuer, ptr, size, fd);
+   smx_action_t action = SIMIX_file_write(simcall->issuer, fd,  size);
    xbt_fifo_push(action->simcalls, simcall);
    simcall->issuer->waiting_action = action;
  }
  
- smx_action_t SIMIX_file_write(smx_process_t process, const void* ptr,
-                               size_t size, smx_file_t fd)
+ smx_action_t SIMIX_file_write(smx_process_t process, smx_file_t fd, sg_storage_size_t size)
  {
    smx_action_t action;
    smx_host_t host = process->smx_host;
  
    /* check if the host is active */
 -  if (surf_workstation_model->extension.
 -      workstation.get_state(host) != SURF_RESOURCE_ON) {
 +  if (surf_resource_get_state(surf_workstation_resource_priv(host)) != SURF_RESOURCE_ON) {
      THROWF(host_error, 0, "Host %s failed, you cannot call this function",
             sg_host_name(host));
    }
  #endif
  
    action->io.host = host;
-   action->io.surf_io = surf_workstation_write(host, ptr, size, fd->surf_file);
 -  action->io.surf_io =
 -      surf_workstation_model->extension.workstation.write(host, fd->surf_file, size);
++  action->io.surf_io = surf_workstation_write(host, fd->surf_file, size);
  
 -  surf_workstation_model->action_data_set(action->io.surf_io, action);
 +  surf_action_set_data(action->io.surf_io, action);
    XBT_DEBUG("Create io action %p", action);
  
    return action;
@@@ -105,7 -160,8 +156,7 @@@ smx_action_t SIMIX_file_open(smx_proces
    smx_host_t host = process->smx_host;
  
    /* check if the host is active */
 -  if (surf_workstation_model->extension.
 -      workstation.get_state(host) != SURF_RESOURCE_ON) {
 +  if (surf_resource_get_state(surf_workstation_resource_priv(host)) != SURF_RESOURCE_ON) {
      THROWF(host_error, 0, "Host %s failed, you cannot call this function",
             sg_host_name(host));
    }
  #endif
  
    action->io.host = host;
 -  action->io.surf_io =
 -      surf_workstation_model->extension.workstation.open(host, mount, path);
 +  action->io.surf_io = surf_workstation_open(host, mount, path);
  
 -  surf_workstation_model->action_data_set(action->io.surf_io, action);
 +  surf_action_set_data(action->io.surf_io, action);
    XBT_DEBUG("Create io action %p", action);
  
    return action;
@@@ -140,7 -197,8 +191,7 @@@ smx_action_t SIMIX_file_close(smx_proce
    smx_host_t host = process->smx_host;
  
    /* check if the host is active */
 -  if (surf_workstation_model->extension.
 -      workstation.get_state(host) != SURF_RESOURCE_ON) {
 +  if (surf_resource_get_state(surf_workstation_resource_priv(host)) != SURF_RESOURCE_ON) {
      THROWF(host_error, 0, "Host %s failed, you cannot call this function",
             sg_host_name(host));
    }
  #endif
  
    action->io.host = host;
 -  action->io.surf_io = surf_workstation_model->extension.workstation.close(host, fd->surf_file);
 +  action->io.surf_io = surf_workstation_close(host, fd->surf_file);
  
 -  surf_workstation_model->action_data_set(action->io.surf_io, action);
 +  surf_action_set_data(action->io.surf_io, action);
    XBT_DEBUG("Create io action %p", action);
  
    return action;
@@@ -172,13 -230,14 +223,13 @@@ int SIMIX_file_unlink(smx_process_t pro
  {
    smx_host_t host = process->smx_host;
    /* check if the host is active */
 -  if (surf_workstation_model->extension.
 -      workstation.get_state(host) != SURF_RESOURCE_ON) {
 +  if (surf_resource_get_state(surf_workstation_resource_priv(host)) != SURF_RESOURCE_ON) {
      THROWF(host_error, 0, "Host %s failed, you cannot call this function",
             sg_host_name(host));
    }
  
 -  if (surf_workstation_model->extension.workstation.unlink(host, fd->surf_file)){
 +  if (surf_workstation_unlink(host, fd->surf_file)){
-     fd->surf_file = NULL;
+     xbt_free(fd);
      return 1;
    } else
      return 0;
@@@ -197,7 -256,7 +248,7 @@@ smx_action_t SIMIX_file_ls(smx_process_
    smx_action_t action;
    smx_host_t host = process->smx_host;
    /* check if the host is active */
 -  if (surf_workstation_model->extension.workstation.get_state(host) != SURF_RESOURCE_ON) {
 +  if (surf_resource_get_state(surf_workstation_resource_priv(host)) != SURF_RESOURCE_ON) {
      THROWF(host_error, 0, "Host %s failed, you cannot call this function",
             sg_host_name(host));
    }
  #endif
  
    action->io.host = host;
 -  action->io.surf_io = surf_workstation_model->extension.workstation.ls(host,mount,path);
 +  action->io.surf_io = surf_workstation_ls(host,mount,path);
  
 -  surf_workstation_model->action_data_set(action->io.surf_io, action);
 +  surf_action_set_data(action->io.surf_io, action);
    XBT_DEBUG("Create io action %p", action);
    return action;
  }
  
- size_t SIMIX_pre_file_get_size(smx_simcall_t simcall, smx_file_t fd)
+ sg_storage_size_t SIMIX_pre_file_get_size(smx_simcall_t simcall, smx_file_t fd)
  {
    return SIMIX_file_get_size(simcall->issuer, fd);
  }
  
- size_t SIMIX_file_get_size(smx_process_t process, smx_file_t fd)
+ sg_storage_size_t SIMIX_file_get_size(smx_process_t process, smx_file_t fd)
  {
    smx_host_t host = process->smx_host;
 -  return  surf_workstation_model->extension.workstation.get_size(host,
 -      fd->surf_file);
 +  return  surf_workstation_get_size(host, fd->surf_file);
  }
  
 -  return  surf_workstation_model->extension.workstation.get_info(host,
 -      fd->surf_file);
+ xbt_dynar_t SIMIX_pre_file_get_info(smx_simcall_t simcall, smx_file_t fd)
+ {
+   return SIMIX_file_get_info(simcall->issuer, fd);
+ }
+ xbt_dynar_t SIMIX_file_get_info(smx_process_t process, smx_file_t fd)
+ {
+   smx_host_t host = process->smx_host;
 -  return  surf_workstation_model->extension.workstation.get_free_size(host,name);
++  return  surf_workstation_get_info(host, fd->surf_file);
+ }
+ sg_storage_size_t SIMIX_pre_storage_get_free_size(smx_simcall_t simcall, const char* name)
+ {
+   return SIMIX_storage_get_free_size(simcall->issuer, name);
+ }
+ sg_storage_size_t SIMIX_storage_get_free_size(smx_process_t process, const char* name)
+ {
+   smx_host_t host = process->smx_host;
 -  return  surf_workstation_model->extension.workstation.get_used_size(host,name);
++  return  surf_workstation_get_free_size(host, name);
+ }
+ sg_storage_size_t SIMIX_pre_storage_get_used_size(smx_simcall_t simcall, const char* name)
+ {
+   return SIMIX_storage_get_used_size(simcall->issuer, name);
+ }
+ sg_storage_size_t SIMIX_storage_get_used_size(smx_process_t process, const char* name)
+ {
+   smx_host_t host = process->smx_host;
 -  return surf_storage_model->extension.storage.get_properties(storage);
++  return  surf_workstation_get_used_size(host, name);
+ }
+ xbt_dict_t SIMIX_pre_storage_get_properties(smx_simcall_t simcall, smx_storage_t storage){
+   return SIMIX_storage_get_properties(storage);
+ }
+ xbt_dict_t SIMIX_storage_get_properties(smx_storage_t storage){
+   xbt_assert((storage != NULL), "Invalid parameters (simix storage is NULL)");
 -  return surf_storage_model->extension.storage.get_content(storage);
++  return surf_resource_get_properties(surf_workstation_resource_priv(storage));
+ }
+ const char* SIMIX_pre_storage_get_name(smx_simcall_t simcall, smx_storage_t storage){
+    return SIMIX_storage_get_name(storage);
+ }
+ const char* SIMIX_storage_get_name(smx_storage_t storage){
+   xbt_assert((storage != NULL), "Invalid parameters");
+   return sg_storage_name(storage);
+ }
+ void SIMIX_pre_storage_set_data(smx_simcall_t simcall, smx_storage_t storage, void *data) {
+   SIMIX_storage_set_data(storage, data);
+ }
+ void SIMIX_storage_set_data(smx_storage_t storage, void *data){
+   xbt_assert((storage != NULL), "Invalid parameters");
+   xbt_assert((SIMIX_storage_priv(storage)->data == NULL), "Data already set");
+   SIMIX_storage_priv(storage)->data = data;
+ }
+ void* SIMIX_pre_storage_get_data(smx_simcall_t simcall,smx_storage_t storage){
+   return SIMIX_storage_get_data(storage);
+ }
+ void* SIMIX_storage_get_data(smx_storage_t storage){
+   xbt_assert((storage != NULL), "Invalid parameters (simix storage is NULL)");
+   return SIMIX_storage_priv(storage)->data;
+ }
+ xbt_dict_t SIMIX_pre_storage_get_content(smx_simcall_t simcall, smx_storage_t storage){
+   return SIMIX_storage_get_content(storage);
+ }
+ xbt_dict_t SIMIX_storage_get_content(smx_storage_t storage){
+   xbt_assert((storage != NULL), "Invalid parameters (simix storage is NULL)");
 -  return surf_storage_model->extension.storage.get_size(storage);
++  return surf_storage_get_content(storage);
+ }
+ sg_storage_size_t SIMIX_storage_get_size(smx_storage_t storage){
+   xbt_assert((storage != NULL), "Invalid parameters (simix storage is NULL)");
++  return surf_storage_get_size(storage);
+ }
  
  void SIMIX_post_io(smx_action_t action)
  {
      switch (simcall->call) {
      case SIMCALL_FILE_OPEN:;
        smx_file_t tmp = xbt_new(s_smx_file_t,1);
 -      tmp->surf_file = (action->io.surf_io)->file;
 +      tmp->surf_file = surf_storage_action_get_file(action->io.surf_io);
        simcall_file_open__set__result(simcall, tmp);
        break;
  
        xbt_free(simcall_file_close__get__fd(simcall));
        simcall_file_close__set__result(simcall, 0);
        break;
 -
      case SIMCALL_FILE_WRITE:
 -      simcall_file_write__set__result(simcall, (action->io.surf_io)->cost);
 +      simcall_file_write__set__result(simcall, surf_action_get_cost(action->io.surf_io));
        break;
  
      case SIMCALL_FILE_READ:
 -      simcall_file_read__set__result(simcall, (action->io.surf_io)->cost);
 +      simcall_file_read__set__result(simcall, surf_action_get_cost(action->io.surf_io));
        break;
  
      case SIMCALL_FILE_LS:
  //          xbt_dict_set((action->io.surf_io)->ls_dict,key,dst,xbt_free);
  //        }
  //      }
 -      simcall_file_ls__set__result(simcall, (action->io.surf_io)->ls_dict);
 +      simcall_file_ls__set__result(simcall, surf_storage_action_get_ls_dict(action->io.surf_io));
        break;
      default:
        break;
      }
    }
  
 -  switch (surf_workstation_model->action_state_get(action->io.surf_io)) {
 +  switch (surf_action_get_state(action->io.surf_io)) {
  
      case SURF_ACTION_FAILED:
        action->state = SIMIX_FAILED;
@@@ -296,7 -441,7 +430,7 @@@ void SIMIX_io_destroy(smx_action_t acti
  {
    XBT_DEBUG("Destroy action %p", action);
    if (action->io.surf_io)
 -    action->io.surf_io->model_type->action_unref(action->io.surf_io);
 +    surf_action_unref(action->io.surf_io);
    xbt_mallocator_release(simix_global->action_mallocator, action);
  }
  
@@@ -326,7 -471,8 +460,7 @@@ void SIMIX_io_finish(smx_action_t actio
              (int)action->state);
      }
  
 -    if (surf_workstation_model->extension.
 -        workstation.get_state(simcall->issuer->smx_host) != SURF_RESOURCE_ON) {
 +    if (surf_resource_get_state(surf_workstation_resource_priv(simcall->issuer->smx_host)) != SURF_RESOURCE_ON) {
        simcall->issuer->context->iwannadie = 1;
      }
  
diff --combined src/simix/smx_network.c
@@@ -1,4 -1,4 +1,4 @@@
- /* Copyright (c) 2009, 2010. The SimGrid Team.
+ /* Copyright (c) 2009-2013. The SimGrid Team.
   * All rights reserved.                                                     */
  
  /* This program is free software; you can redistribute it and/or modify it
@@@ -31,7 -31,7 +31,7 @@@ void SIMIX_network_init(void
  {
    rdv_points = xbt_dict_new_homogeneous(SIMIX_rdv_free);
    if(MC_is_active())
-     MC_ignore_data_bss(&smx_total_comms, sizeof(smx_total_comms));
+     MC_ignore_global_variable("smx_total_comms");
  }
  
  void SIMIX_network_exit(void)
@@@ -340,17 -340,17 +340,17 @@@ void SIMIX_comm_destroy_internal_action
  #ifdef HAVE_LATENCY_BOUND_TRACKING
      action->latency_limited = SIMIX_comm_is_latency_bounded(action);
  #endif
 -    action->comm.surf_comm->model_type->action_unref(action->comm.surf_comm);
 +    surf_action_unref(action->comm.surf_comm);
      action->comm.surf_comm = NULL;
    }
  
    if (action->comm.src_timeout){
 -    action->comm.src_timeout->model_type->action_unref(action->comm.src_timeout);
 +    surf_action_unref(action->comm.src_timeout);
      action->comm.src_timeout = NULL;
    }
  
    if (action->comm.dst_timeout){
 -    action->comm.dst_timeout->model_type->action_unref(action->comm.dst_timeout);
 +    surf_action_unref(action->comm.dst_timeout);
      action->comm.dst_timeout = NULL;
    }
  }
@@@ -695,7 -695,6 +695,6 @@@ smx_action_t SIMIX_comm_iprobe(smx_proc
  
  void SIMIX_pre_comm_wait(smx_simcall_t simcall, smx_action_t action, double timeout)
  {
-   int idx = simcall->mc_value;
    /* the simcall may be a wait, a send or a recv */
    surf_action_t sleep;
  
    simcall->issuer->waiting_action = action;
  
    if (MC_is_active()) {
+     int idx = simcall->mc_value;
      if (idx == 0) {
        action->state = SIMIX_DONE;
      } else {
    if (action->state != SIMIX_WAITING && action->state != SIMIX_RUNNING) {
      SIMIX_comm_finish(action);
    } else { /* if (timeout >= 0) { we need a surf sleep action even when there is no timeout, otherwise surf won't tell us when the host fails */
 -    sleep = surf_workstation_model->extension.workstation.sleep(simcall->issuer->smx_host, timeout);
 -    surf_workstation_model->action_data_set(sleep, action);
 +    sleep = surf_workstation_sleep(simcall->issuer->smx_host, timeout);
 +    surf_action_set_data(sleep, action);
  
      if (simcall->issuer == action->comm.src_proc)
        action->comm.src_timeout = sleep;
@@@ -764,12 -764,12 +764,12 @@@ void SIMIX_pre_comm_test(smx_simcall_t 
  
  void SIMIX_pre_comm_testany(smx_simcall_t simcall, xbt_dynar_t actions)
  {
-   int idx = simcall->mc_value;
    unsigned int cursor;
    smx_action_t action;
    simcall_comm_testany__set__result(simcall, -1);
  
    if (MC_is_active()){
+     int idx = simcall->mc_value;
      if(idx == -1){
        SIMIX_simcall_answer(simcall);
      }else{
  
  void SIMIX_pre_comm_waitany(smx_simcall_t simcall, xbt_dynar_t actions)
  {
-   int idx = simcall->mc_value;
    smx_action_t action;
    unsigned int cursor = 0;
  
    if (MC_is_active()){
+     int idx = simcall->mc_value;
      action = xbt_dynar_get_as(actions, idx, smx_action_t);
      xbt_fifo_push(action->simcalls, simcall);
      simcall_comm_waitany__set__result(simcall, idx);
@@@ -846,16 -846,15 +846,16 @@@ XBT_INLINE void SIMIX_comm_start(smx_ac
      XBT_DEBUG("Starting communication %p from '%s' to '%s'", action,
                SIMIX_host_get_name(sender), SIMIX_host_get_name(receiver));
  
 -    action->comm.surf_comm = surf_workstation_model->extension.workstation.
 -      communicate(sender, receiver, action->comm.task_size, action->comm.rate);
 +    action->comm.surf_comm = surf_workstation_model_communicate(surf_workstation_model,
 +                                                                  sender, receiver,
 +                                                                  action->comm.task_size, action->comm.rate);
  
 -    surf_workstation_model->action_data_set(action->comm.surf_comm, action);
 +    surf_action_set_data(action->comm.surf_comm, action);
  
      action->state = SIMIX_RUNNING;
  
      /* If a link is failed, detect it immediately */
 -    if (surf_workstation_model->action_state_get(action->comm.surf_comm) == SURF_ACTION_FAILED) {
 +    if (surf_action_get_state(action->comm.surf_comm) == SURF_ACTION_FAILED) {
        XBT_DEBUG("Communication from '%s' to '%s' failed to start because of a link failure",
                  SIMIX_host_get_name(sender), SIMIX_host_get_name(receiver));
        action->state = SIMIX_LINK_FAILURE;
          XBT_DEBUG("The communication is suspended on startup because dst (%s:%s) were suspended since it initiated the communication",
                    SIMIX_host_get_name(action->comm.dst_proc->smx_host), action->comm.dst_proc->name);
  
 -      surf_workstation_model->suspend(action->comm.surf_comm);
 +      surf_action_suspend(action->comm.surf_comm);
  
      }
    }
@@@ -981,7 -980,8 +981,7 @@@ void SIMIX_comm_finish(smx_action_t act
        }
      }
  
 -    if (surf_workstation_model->extension.
 -        workstation.get_state(simcall->issuer->smx_host) != SURF_RESOURCE_ON) {
 +    if (surf_resource_get_state(surf_workstation_resource_priv(simcall->issuer->smx_host)) != SURF_RESOURCE_ON) {
        simcall->issuer->context->iwannadie = 1;
      }
  
@@@ -1013,19 -1013,19 +1013,19 @@@ void SIMIX_post_comm(smx_action_t actio
  {
    /* Update action state */
    if (action->comm.src_timeout &&
 -      surf_workstation_model->action_state_get(action->comm.src_timeout) == SURF_ACTION_DONE)
 +      surf_action_get_state(action->comm.src_timeout) == SURF_ACTION_DONE)
      action->state = SIMIX_SRC_TIMEOUT;
    else if (action->comm.dst_timeout &&
 -           surf_workstation_model->action_state_get(action->comm.dst_timeout) == SURF_ACTION_DONE)
 +        surf_action_get_state(action->comm.dst_timeout) == SURF_ACTION_DONE)
      action->state = SIMIX_DST_TIMEOUT;
    else if (action->comm.src_timeout &&
 -           surf_workstation_model->action_state_get(action->comm.src_timeout) == SURF_ACTION_FAILED)
 +        surf_action_get_state(action->comm.src_timeout) == SURF_ACTION_FAILED)
      action->state = SIMIX_SRC_HOST_FAILURE;
    else if (action->comm.dst_timeout &&
 -           surf_workstation_model->action_state_get(action->comm.dst_timeout) == SURF_ACTION_FAILED)
 +      surf_action_get_state(action->comm.dst_timeout) == SURF_ACTION_FAILED)
      action->state = SIMIX_DST_HOST_FAILURE;
    else if (action->comm.surf_comm &&
 -           surf_workstation_model->action_state_get(action->comm.surf_comm) == SURF_ACTION_FAILED) {
 +        surf_action_get_state(action->comm.surf_comm) == SURF_ACTION_FAILED) {
      XBT_DEBUG("Puta madre. Surf says that the link broke");
      action->state = SIMIX_LINK_FAILURE;
    } else
@@@ -1066,7 -1066,7 +1066,7 @@@ void SIMIX_comm_cancel(smx_action_t act
    else if (!MC_is_active() /* when running the MC there are no surf actions */
             && (action->state == SIMIX_READY || action->state == SIMIX_RUNNING)) {
  
 -    surf_workstation_model->action_cancel(action->comm.surf_comm);
 +    surf_action_cancel(action->comm.surf_comm);
    }
  }
  
@@@ -1074,7 -1074,7 +1074,7 @@@ void SIMIX_comm_suspend(smx_action_t ac
  {
    /*FIXME: shall we suspend also the timeout actions? */
    if (action->comm.surf_comm)
 -    surf_workstation_model->suspend(action->comm.surf_comm);
 +    surf_action_suspend(action->comm.surf_comm);
    /* in the other case, the action will be suspended on creation, in SIMIX_comm_start() */
  }
  
@@@ -1082,7 -1082,7 +1082,7 @@@ void SIMIX_comm_resume(smx_action_t act
  {
    /*FIXME: check what happen with the timeouts */
    if (action->comm.surf_comm)
 -    surf_workstation_model->resume(action->comm.surf_comm);
 +    surf_action_resume(action->comm.surf_comm);
    /* in the other case, the action were not really suspended yet, see SIMIX_comm_suspend() and SIMIX_comm_start() */
  }
  
@@@ -1107,7 -1107,7 +1107,7 @@@ double SIMIX_comm_get_remains(smx_actio
    switch (action->state) {
  
    case SIMIX_RUNNING:
 -    remains = surf_workstation_model->get_remains(action->comm.surf_comm);
 +    remains = surf_action_get_remains(action->comm.surf_comm);
      break;
  
    case SIMIX_WAITING:
diff --combined src/simix/smx_new_api.c
@@@ -1,4 -1,4 +1,4 @@@
- /* Copyright (c) 2007, 2008, 2009, 2010. The SimGrid Team.
+ /* Copyright (c) 2007-2010, 2012-2013. The SimGrid Team.
   * All rights reserved.                                                     */
  
  /* This program is free software; you can redistribute it and/or modify it
@@@ -43,7 -43,7 +43,7 @@@ void SIMIX_post_new_api(smx_action_t ac
      }
    }
  
 -  switch (surf_workstation_model->action_state_get(action->new_api.surf_new_api)) {
 +  switch (surf_action_get_state(action->new_api.surf_new_api)) {
  
      case SURF_ACTION_FAILED:
        action->state = SIMIX_FAILED;
@@@ -67,7 -67,8 +67,7 @@@ smx_action_t SIMIX_new_api_fct(smx_proc
    smx_host_t host = process->smx_host;
  
    /* check if the host is active */
 -  if (surf_workstation_model->extension.
 -      workstation.get_state(host) != SURF_RESOURCE_ON) {
 +  if (surf_resource_get_state(surf_workstation_resource_priv(host)) != SURF_RESOURCE_ON) {
      THROWF(host_error, 0, "Host %s failed, you cannot call this function",
             sg_host_name(host));
    }
@@@ -80,9 -81,9 +80,9 @@@
  #endif
  
    // Called the function from the new model
 -  action->new_api.surf_new_api = surf_workstation_model->extension.new_model.fct();
 +  //FIXME:CHECK WHAT TO DO action->new_api.surf_new_api = surf_workstation_model->extension.new_model.fct();
  
 -  surf_workstation_model->action_data_set(action->new_api.surf_new_api, action);
 +  surf_action_set_data(action->new_api.surf_new_api, action);
    XBT_DEBUG("Create NEW MODEL action %p", action);
  
    return action;
@@@ -92,7 -93,7 +92,7 @@@ void SIMIX_new_api_destroy(smx_action_
  {
    XBT_DEBUG("Destroy action %p", action);
    if (action->new_api.surf_new_api)
 -    action->new_api.surf_new_api->model_type->action_unref(action->new_api.surf_new_api);
 +    surf_action_unref(action->new_api.surf_new_api);
    xbt_mallocator_release(simix_global->action_mallocator, action);
  }
  
@@@ -122,7 -123,8 +122,7 @@@ void SIMIX_new_api_finish(smx_action_t 
              (int)action->state);
      }
  
 -    if (surf_workstation_model->extension.
 -        workstation.get_state(simcall->issuer->smx_host) != SURF_RESOURCE_ON) {
 +    if (surf_resource_get_state(surf_workstation_resource_priv(simcall->issuer->smx_host)) != SURF_RESOURCE_ON) {
        simcall->issuer->context->iwannadie = 1;
      }
  
diff --combined src/simix/smx_process.c
@@@ -1,4 -1,4 +1,4 @@@
- /* Copyright (c) 2007-2012. The SimGrid Team.
+ /* Copyright (c) 2007-2013. The SimGrid Team.
   * All rights reserved.                                                     */
  
  /* This program is free software; you can redistribute it and/or modify it
@@@ -122,8 -122,8 +122,8 @@@ void SIMIX_process_empty_trash(void
  
      xbt_dynar_free(&process->on_exit);
  
-     free(process->name);
-     free(process);
+     xbt_free(process->name);
+     xbt_free(process);
    }
  }
  
@@@ -239,8 -239,12 +239,12 @@@ void SIMIX_process_create(smx_process_
    XBT_DEBUG("Start process %s on host '%s'", name, hostname);
  
    if (!SIMIX_host_get_state(host)) {
+     int i;
      XBT_WARN("Cannot launch process '%s' on failed host '%s'", name,
            hostname);
+     for (i = 0; i < argc; i++)
+       xbt_free(argv[i]);
+     xbt_free(argv);
    }
    else {
      *process = xbt_new0(s_smx_process_t, 1);
@@@ -691,7 -695,8 +695,7 @@@ smx_action_t SIMIX_process_sleep(smx_pr
    smx_host_t host = process->smx_host;
  
    /* check if the host is active */
 -  if (surf_workstation_model->extension.
 -      workstation.get_state(host) != SURF_RESOURCE_ON) {
 +  if (surf_resource_get_state(surf_workstation_resource_priv(host)) != SURF_RESOURCE_ON) {
      THROWF(host_error, 0, "Host %s failed, you cannot call this function",
             sg_host_name(host));
    }
  
    action->sleep.host = host;
    action->sleep.surf_sleep =
 -      surf_workstation_model->extension.workstation.sleep(host, duration);
 +      surf_workstation_sleep(host, duration);
  
 -  surf_workstation_model->action_data_set(action->sleep.surf_sleep, action);
 +  surf_action_set_data(action->sleep.surf_sleep, action);
    XBT_DEBUG("Create sleep action %p", action);
  
    return action;
@@@ -720,7 -725,7 +724,7 @@@ void SIMIX_post_process_sleep(smx_actio
  
    while ((simcall = xbt_fifo_shift(action->simcalls))) {
  
 -    switch(surf_workstation_model->action_state_get(action->sleep.surf_sleep)){
 +    switch(surf_action_get_state(action->sleep.surf_sleep)){
        case SURF_ACTION_FAILED:
          simcall->issuer->context->iwannadie = 1;
          //SMX_EXCEPTION(simcall->issuer, host_error, 0, "Host failed");
          THROW_IMPOSSIBLE;
          break;
      }
 -    if (surf_workstation_model->extension.
 -        workstation.get_state(simcall->issuer->smx_host) != SURF_RESOURCE_ON) {
 +    if (surf_resource_get_state(surf_workstation_resource_priv(simcall->issuer->smx_host)) != SURF_RESOURCE_ON) {
        simcall->issuer->context->iwannadie = 1;
      }
      simcall_process_sleep__set__result(simcall, state);
@@@ -750,18 -756,18 +754,18 @@@ void SIMIX_process_sleep_destroy(smx_ac
  {
    XBT_DEBUG("Destroy action %p", action);
    if (action->sleep.surf_sleep)
 -    action->sleep.surf_sleep->model_type->action_unref(action->sleep.surf_sleep);
 +    surf_action_unref(action->sleep.surf_sleep);
    xbt_mallocator_release(simix_global->action_mallocator, action);
  }
  
  void SIMIX_process_sleep_suspend(smx_action_t action)
  {
 -  surf_workstation_model->suspend(action->sleep.surf_sleep);
 +  surf_action_suspend(action->sleep.surf_sleep);
  }
  
  void SIMIX_process_sleep_resume(smx_action_t action)
  {
 -  surf_workstation_model->resume(action->sleep.surf_sleep);
 +  surf_action_resume(action->sleep.surf_sleep);
  }
  
  /** 
@@@ -1,4 -1,4 +1,4 @@@
- /* Copyright (c) 2007, 2008, 2009, 2010. The SimGrid Team.
+ /* Copyright (c) 2007-2010, 2012-2013. The SimGrid Team.
   * All rights reserved.                                                     */
  
  /* This program is free software; you can redistribute it and/or modify it
  #define TULONG(n) (n, unsigned long, ul)
  #define TFLOAT(n) (n, float, f)
  #define TDOUBLE(n) (n, double, d)
 -#define TPTR(n) (n, void*, p)
 +#define TDPTR(n) (n, void*, dp, void*)
 +#define TFPTR(n) (n, FPtr, fp, FPtr)
  #define TCPTR(n) (n, const void*, cp)
  #define TSIZE(n) (n, size_t, si)
  #define TVOID(n) (n, void)
 -#define TSPEC(n,t) (n, t, p)
 +#define TDSPEC(n,t) (n, t, dp, void*)
 +#define TFSPEC(n,t) (n, t, fp, FPtr)
  
  /* use comma or nothing to separate elements*/
  #define SIMCALL_SEP_COMMA ,
  #define SIMCALL_SEP_NOTHING
  
  /* get the name of the parameter */
 -#define SIMCALL_NAME_(name, type, field) name
 +#define SIMCALL_NAME_(name, type, field, ...) name
  #define SIMCALL_NAME(i, v) SIMCALL_NAME_ v
  
 +/* get the cast of the parameter */
 +#define SIMCALL_CASTTYPE_(name, type, field, cast) (cast)
 +#define SIMCALL_NOCASTTYPE_(name, type, field) 
 +#define SIMCALL_CASTTYPE(...) MAYBE5(,##__VA_ARGS__, SIMCALL_CASTTYPE_, SIMCALL_NOCASTTYPE_) (__VA_ARGS__)
 +
 +/* get the uncast of the parameter */
 +#define SIMCALL_UNCASTTYPE_(name, type, field, cast) (type)
 +#define SIMCALL_NOUNCASTTYPE_(name, type, field) 
 +#define SIMCALL_UNCASTTYPE(...) MAYBE5(,##__VA_ARGS__, SIMCALL_UNCASTTYPE_, SIMCALL_NOUNCASTTYPE_) (__VA_ARGS__)
 +
  /* get the %s format code of the parameter */
 -#define SIMCALL_FORMAT_(name, type, field) %field
 +#define SIMCALL_FORMAT_(name, type, field, ...) %field
  #define SIMCALL_FORMAT(i, v) SIMCALL_FORMAT_ v
  
  /* get the field of the parameter */
 -#define SIMCALL_FIELD_(name, type, field) field
 +#define SIMCALL_FIELD_(name, type, field, ...) field
  #define SIMCALL_FIELD(i, v) SIMCALL_FIELD_ v
  
  /* get the parameter declaration */
 -#define SIMCALL_ARG_(name, type, field) type name
 +#define SIMCALL_ARG_(name, type, field, ...) type name
  #define SIMCALL_ARG(i, v) SIMCALL_ARG_ v
  
  /* get the parameter initialisation field */
 -#define SIMCALL_INIT_FIELD_(name, type, field) .field = name
 +#define SIMCALL_INIT_FIELD_(name, type, field, ...) .field = SIMCALL_CASTTYPE(name, type, field,##__VA_ARGS__) name
  #define SIMCALL_INIT_FIELD(i, d, v) self->simcall.args[i]SIMCALL_INIT_FIELD_ v;
  
  /* get the case of the parameter */
 -#define SIMCALL_CASE_PARAM_(name, type, field) field
 -#define SIMCALL_CASE_PARAM(i, v) simcall->args[i].SIMCALL_CASE_PARAM_ v
 +#define SIMCALL_CASE_PARAM_(name, type, field, ...) field
 +#define SIMCALL_CASE_PARAM(i, v) SIMCALL_UNCASTTYPE v simcall->args[i].SIMCALL_CASE_PARAM_ v
  
  /* generate some code for SIMCALL_CASE if the simcall has an answer */
 +#define MAYBE5(_0, _1, _2, _3, _4, func, ...) func
 +#define MAYBE3(_0, _1, _2, func, ...) func
  #define MAYBE2(_0, _1, func, ...) func
  
 -#define SIMCALL_WITH_RESULT_BEGIN(name, type, field) simcall->result.field =
 +#define SIMCALL_WITH_RESULT_BEGIN(name, type, field, ...) simcall->result.field =
  #define SIMCALL_WITHOUT_RESULT_BEGIN(name, type, field)
  #define SIMCALL_RESULT_BEGIN_(name, type, ...)\
 -        MAYBE2(,##__VA_ARGS__, SIMCALL_WITH_RESULT_BEGIN, SIMCALL_WITHOUT_RESULT_BEGIN)\
 +        MAYBE3(,##__VA_ARGS__, SIMCALL_WITH_RESULT_BEGIN, SIMCALL_WITH_RESULT_BEGIN, SIMCALL_WITHOUT_RESULT_BEGIN)\
        (name, type, __VA_ARGS__)
  #define SIMCALL_RESULT_BEGIN(answer, res) answer(SIMCALL_RESULT_BEGIN_ res)
  
  #define SIMCALL_WITH_FUNC_SIMCALL(name, type, field) smx_simcall_t simcall = 
  #define SIMCALL_WITHOUT_FUNC_SIMCALL(name, type, field)
  #define SIMCALL_FUNC_SIMCALL_(name, type, ...)\
 -        MAYBE2(,##__VA_ARGS__, SIMCALL_WITH_FUNC_SIMCALL, SIMCALL_WITHOUT_FUNC_SIMCALL)\
 +        MAYBE3(,##__VA_ARGS__, SIMCALL_WITH_FUNC_SIMCALL, SIMCALL_WITH_FUNC_SIMCALL, SIMCALL_WITHOUT_FUNC_SIMCALL)\
        (name, type, __VA_ARGS__)
  #define SIMCALL_FUNC_SIMCALL(res) SIMCALL_FUNC_SIMCALL_ res
  
 -#define SIMCALL_WITH_FUNC_RETURN(name, type, field) return self->simcall.result.field;
 +#define SIMCALL_WITH_FUNC_RETURN(name, type, field, ...) return self->simcall.result.field;
  #define SIMCALL_WITHOUT_FUNC_RETURN(name, type, field)
  #define SIMCALL_FUNC_RETURN_(name, type, ...)\
 -        MAYBE2(,##__VA_ARGS__, SIMCALL_WITH_FUNC_RETURN, SIMCALL_WITHOUT_FUNC_RETURN)\
 +        MAYBE3(,##__VA_ARGS__, SIMCALL_WITH_FUNC_RETURN, SIMCALL_WITH_FUNC_RETURN, SIMCALL_WITHOUT_FUNC_RETURN)\
        (name, type, __VA_ARGS__)
  #define SIMCALL_FUNC_RETURN(res) SIMCALL_FUNC_RETURN_ res
  
  /* generate the simcalls args getter/setter */
  #define SIMCALL_ARG_GETSET_(i, name, v) \
    static inline SIMCALL_FUNC_RETURN_TYPE(v) SIMCALL_GS_FUNC(SIMCALL_GS_SC_NAME(name), get, SIMCALL_GS_ARG_NAME(v))(smx_simcall_t simcall){\
 -    return simcall->args[i].SIMCALL_FIELD_ v ;\
 +    return (SIMCALL_FUNC_RETURN_TYPE(v)) simcall->args[i].SIMCALL_FIELD_ v ;\
    }\
    static inline void SIMCALL_GS_FUNC(SIMCALL_GS_SC_NAME(name), set, SIMCALL_GS_ARG_NAME(v))(smx_simcall_t simcall, SIMCALL_ARG_ v){\
 -    simcall->args[i].SIMCALL_FIELD_ v = SIMCALL_NAME_ v ;\
 +    simcall->args[i].SIMCALL_FIELD_ v = SIMCALL_CASTTYPE v SIMCALL_NAME_ v ;\
    }
  
  #define SIMCALL_ARG_GETSET(type, name, answer, res, ...)\
  /* generate the simcalls result getter/setter */
  #define SIMCALL_WITH_RES_GETSET(name, v) \
    static inline SIMCALL_FUNC_RETURN_TYPE(v) SIMCALL_GS_FUNC(SIMCALL_GS_SC_NAME((name)), get, SIMCALL_GS_ARG_NAME(v))(smx_simcall_t simcall){\
 -    return simcall->result.SIMCALL_FIELD_ v ;\
 +    return (SIMCALL_FUNC_RETURN_TYPE(v)) simcall->result.SIMCALL_FIELD_ v ;\
    }\
    static inline void SIMCALL_GS_FUNC(SIMCALL_GS_SC_NAME((name)), set, SIMCALL_GS_ARG_NAME(v))(smx_simcall_t simcall, SIMCALL_ARG_ v){\
      simcall->result.SIMCALL_FIELD_ v = SIMCALL_NAME_ v ;\
    }
  #define SIMCALL_WITHOUT_RES_GETSET(name, v)
  #define SIMCALL_RES_GETSET__(name, type, ...)\
 -        MAYBE2(,##__VA_ARGS__, SIMCALL_WITH_RES_GETSET, SIMCALL_WITHOUT_RES_GETSET)
 +        MAYBE3(,##__VA_ARGS__, SIMCALL_WITH_RES_GETSET, SIMCALL_WITH_RES_GETSET, SIMCALL_WITHOUT_RES_GETSET)
  #define SIMCALL_RES_GETSET_(scname, v)\
          SIMCALL_RES_GETSET__ v (scname, v)
  #define SIMCALL_RES_GETSET(type, name, answer, res, ...)\
    inline void SIMCALL_GS_FUNC(SIMCALL_GS_SC_NAME((name)), set, SIMCALL_GS_ARG_NAME(v))(smx_simcall_t simcall, SIMCALL_ARG_ v);
  #define SIMCALL_WITHOUT_RES_GETSET_PROTO(name, v)
  #define SIMCALL_RES_GETSET_PROTO__(name, type, ...)\
 -        MAYBE2(,##__VA_ARGS__, SIMCALL_WITH_RES_GETSET_PROTO, SIMCALL_WITHOUT_RES_GETSET_PROTO)
 +        MAYBE3(,##__VA_ARGS__, SIMCALL_WITH_RES_GETSET_PROTO, SIMCALL_WITHOUT_RES_GETSET_PROTO, SIMCALL_WITHOUT_RES_GETSET_PROTO)
  #define SIMCALL_RES_GETSET_PROTO_(scname, v)\
          SIMCALL_RES_GETSET_PROTO__ v (scname, v)
  #define SIMCALL_RES_GETSET_PROTO(type, name, answer, res, ...)\
  
  /* the list of simcalls definitions */
  #define SIMCALL_LIST1(ACTION, sep) \
 -ACTION(SIMCALL_HOST_GET_BY_NAME, host_get_by_name, WITH_ANSWER, TSPEC(result, smx_host_t), TSTRING(name)) sep \
 -ACTION(SIMCALL_HOST_GET_NAME, host_get_name, WITH_ANSWER, TSTRING(result), TSPEC(host, smx_host_t)) sep \
 -ACTION(SIMCALL_HOST_GET_PROPERTIES, host_get_properties, WITH_ANSWER, TSPEC(result, xbt_dict_t), TSPEC(host, smx_host_t)) sep \
 -ACTION(SIMCALL_HOST_GET_CORE, host_get_core, WITH_ANSWER, TINT(result), TSPEC(host, smx_host_t)) sep \
 -ACTION(SIMCALL_HOST_GET_PROCESS_LIST, host_get_process_list, WITH_ANSWER, TSPEC(result, xbt_swag_t), TSPEC(host, smx_host_t)) sep \
 -ACTION(SIMCALL_HOST_GET_SPEED, host_get_speed, WITH_ANSWER, TDOUBLE(result), TSPEC(host, smx_host_t)) sep \
 -ACTION(SIMCALL_HOST_GET_AVAILABLE_SPEED, host_get_available_speed, WITH_ANSWER, TDOUBLE(result), TSPEC(host, smx_host_t)) sep \
 -ACTION(SIMCALL_HOST_GET_STATE, host_get_state, WITH_ANSWER, TINT(result), TSPEC(host, smx_host_t)) sep \
 -ACTION(SIMCALL_HOST_GET_DATA, host_get_data, WITH_ANSWER, TPTR(result), TSPEC(host, smx_host_t)) sep \
 -ACTION(SIMCALL_HOST_SET_DATA, host_set_data, WITH_ANSWER, TVOID(result), TSPEC(host, smx_host_t), TPTR(data)) sep \
 -ACTION(SIMCALL_HOST_GET_CURRENT_POWER_PEAK, host_get_current_power_peak, WITH_ANSWER, TDOUBLE(result), TSPEC(host, smx_host_t)) sep \
 -ACTION(SIMCALL_HOST_GET_POWER_PEAK_AT, host_get_power_peak_at, WITH_ANSWER, TDOUBLE(result), TSPEC(host, smx_host_t), TINT(pstate_index)) sep \
 -ACTION(SIMCALL_HOST_GET_NB_PSTATES, host_get_nb_pstates, WITH_ANSWER, TINT(result), TSPEC(host, smx_host_t)) sep \
 -ACTION(SIMCALL_HOST_SET_POWER_PEAK_AT, host_set_power_peak_at, WITH_ANSWER, TVOID(result), TSPEC(host, smx_host_t), TINT(pstate_index)) sep \
 -ACTION(SIMCALL_HOST_GET_CONSUMED_ENERGY, host_get_consumed_energy, WITH_ANSWER, TDOUBLE(result), TSPEC(host, smx_host_t)) sep \
 -ACTION(SIMCALL_HOST_EXECUTE, host_execute, WITH_ANSWER, TSPEC(result, smx_action_t), TSTRING(name), TSPEC(host, smx_host_t), TDOUBLE(computation_amount), TDOUBLE(priority)) sep \
 -ACTION(SIMCALL_HOST_PARALLEL_EXECUTE, host_parallel_execute, WITH_ANSWER, TSPEC(result, smx_action_t), TSTRING(name), TINT(host_nb), TSPEC(host_list, smx_host_t*), TSPEC(computation_amount, double*), TSPEC(communication_amount, double*), TDOUBLE(amount), TDOUBLE(rate)) sep \
 -ACTION(SIMCALL_HOST_EXECUTION_DESTROY, host_execution_destroy, WITH_ANSWER, TVOID(result), TSPEC(execution, smx_action_t)) sep \
 -ACTION(SIMCALL_HOST_EXECUTION_CANCEL, host_execution_cancel, WITH_ANSWER, TVOID(result), TSPEC(execution, smx_action_t)) sep \
 -ACTION(SIMCALL_HOST_EXECUTION_GET_REMAINS, host_execution_get_remains, WITH_ANSWER, TDOUBLE(result), TSPEC(execution, smx_action_t)) sep \
 -ACTION(SIMCALL_HOST_EXECUTION_GET_STATE, host_execution_get_state, WITH_ANSWER, TINT(result), TSPEC(execution, smx_action_t)) sep \
 -ACTION(SIMCALL_HOST_EXECUTION_SET_PRIORITY, host_execution_set_priority, WITH_ANSWER, TVOID(result), TSPEC(execution, smx_action_t), TDOUBLE(priority)) sep \
 -ACTION(SIMCALL_HOST_EXECUTION_WAIT, host_execution_wait, WITHOUT_ANSWER, TINT(result), TSPEC(execution, smx_action_t)) sep \
 -ACTION(SIMCALL_HOST_GET_STORAGE_LIST, host_get_storage_list, WITH_ANSWER, TSPEC(result, xbt_dict_t), TSPEC(host, smx_host_t)) sep \
 -ACTION(SIMCALL_PROCESS_CREATE, process_create, WITH_ANSWER, TVOID(result), TSPEC(process, smx_process_t*), TSTRING(name), TSPEC(code, xbt_main_func_t), TPTR(data), TSTRING(hostname), TDOUBLE(kill_time), TINT(argc), TSPEC(argv, char**), TSPEC(properties, xbt_dict_t), TINT(auto_restart)) sep \
 -ACTION(SIMCALL_PROCESS_KILL, process_kill, WITH_ANSWER, TVOID(result), TSPEC(process, smx_process_t)) sep \
 +ACTION(SIMCALL_HOST_GET_BY_NAME, host_get_by_name, WITH_ANSWER, TDSPEC(result, smx_host_t), TSTRING(name)) sep \
 +ACTION(SIMCALL_HOST_GET_NAME, host_get_name, WITH_ANSWER, TSTRING(result), TDSPEC(host, smx_host_t)) sep \
 +ACTION(SIMCALL_HOST_GET_PROPERTIES, host_get_properties, WITH_ANSWER, TDSPEC(result, xbt_dict_t), TDSPEC(host, smx_host_t)) sep \
 +ACTION(SIMCALL_HOST_GET_CORE, host_get_core, WITH_ANSWER, TINT(result), TDSPEC(host, smx_host_t)) sep \
++ACTION(SIMCALL_HOST_GET_PROCESS_LIST, host_get_process_list, WITH_ANSWER, TDSPEC(result, xbt_swag_t), TDSPEC(host, smx_host_t)) sep \
 +ACTION(SIMCALL_HOST_GET_SPEED, host_get_speed, WITH_ANSWER, TDOUBLE(result), TDSPEC(host, smx_host_t)) sep \
 +ACTION(SIMCALL_HOST_GET_AVAILABLE_SPEED, host_get_available_speed, WITH_ANSWER, TDOUBLE(result), TDSPEC(host, smx_host_t)) sep \
 +ACTION(SIMCALL_HOST_GET_STATE, host_get_state, WITH_ANSWER, TINT(result), TDSPEC(host, smx_host_t)) sep \
 +ACTION(SIMCALL_HOST_GET_DATA, host_get_data, WITH_ANSWER, TDPTR(result), TDSPEC(host, smx_host_t)) sep \
 +ACTION(SIMCALL_HOST_SET_DATA, host_set_data, WITH_ANSWER, TVOID(result), TDSPEC(host, smx_host_t), TDPTR(data)) sep \
++ACTION(SIMCALL_HOST_GET_CURRENT_POWER_PEAK, host_get_current_power_peak, WITH_ANSWER, TDOUBLE(result), TDSPEC(host, smx_host_t)) sep \
++ACTION(SIMCALL_HOST_GET_POWER_PEAK_AT, host_get_power_peak_at, WITH_ANSWER, TDOUBLE(result), TDSPEC(host, smx_host_t), TINT(pstate_index)) sep \
++ACTION(SIMCALL_HOST_GET_NB_PSTATES, host_get_nb_pstates, WITH_ANSWER, TINT(result), TDSPEC(host, smx_host_t)) sep \
++ACTION(SIMCALL_HOST_SET_POWER_PEAK_AT, host_set_power_peak_at, WITH_ANSWER, TVOID(result), TDSPEC(host, smx_host_t), TINT(pstate_index)) sep \
++ACTION(SIMCALL_HOST_GET_CONSUMED_ENERGY, host_get_consumed_energy, WITH_ANSWER, TDOUBLE(result), TDSPEC(host, smx_host_t)) sep \
 +ACTION(SIMCALL_HOST_EXECUTE, host_execute, WITH_ANSWER, TDSPEC(result, smx_action_t), TSTRING(name), TDSPEC(host, smx_host_t), TDOUBLE(computation_amount), TDOUBLE(priority)) sep \
 +ACTION(SIMCALL_HOST_PARALLEL_EXECUTE, host_parallel_execute, WITH_ANSWER, TDSPEC(result, smx_action_t), TSTRING(name), TINT(host_nb), TDSPEC(host_list, smx_host_t*), TDSPEC(computation_amount, double*), TDSPEC(communication_amount, double*), TDOUBLE(amount), TDOUBLE(rate)) sep \
 +ACTION(SIMCALL_HOST_EXECUTION_DESTROY, host_execution_destroy, WITH_ANSWER, TVOID(result), TDSPEC(execution, smx_action_t)) sep \
 +ACTION(SIMCALL_HOST_EXECUTION_CANCEL, host_execution_cancel, WITH_ANSWER, TVOID(result), TDSPEC(execution, smx_action_t)) sep \
 +ACTION(SIMCALL_HOST_EXECUTION_GET_REMAINS, host_execution_get_remains, WITH_ANSWER, TDOUBLE(result), TDSPEC(execution, smx_action_t)) sep \
 +ACTION(SIMCALL_HOST_EXECUTION_GET_STATE, host_execution_get_state, WITH_ANSWER, TINT(result), TDSPEC(execution, smx_action_t)) sep \
 +ACTION(SIMCALL_HOST_EXECUTION_SET_PRIORITY, host_execution_set_priority, WITH_ANSWER, TVOID(result), TDSPEC(execution, smx_action_t), TDOUBLE(priority)) sep \
 +ACTION(SIMCALL_HOST_EXECUTION_WAIT, host_execution_wait, WITHOUT_ANSWER, TINT(result), TDSPEC(execution, smx_action_t)) sep \
++ACTION(SIMCALL_HOST_GET_STORAGE_LIST, host_get_storage_list, WITH_ANSWER, TDSPEC(result, xbt_dict_t), TDSPEC(host, smx_host_t)) sep \
 +ACTION(SIMCALL_PROCESS_CREATE, process_create, WITH_ANSWER, TVOID(result), TDSPEC(process, smx_process_t*), TSTRING(name), TFSPEC(code, xbt_main_func_t), TDPTR(data), TSTRING(hostname), TDOUBLE(kill_time), TINT(argc), TDSPEC(argv, char**), TDSPEC(properties, xbt_dict_t), TINT(auto_restart)) sep \
 +ACTION(SIMCALL_PROCESS_KILL, process_kill, WITH_ANSWER, TVOID(result), TDSPEC(process, smx_process_t)) sep \
  ACTION(SIMCALL_PROCESS_KILLALL, process_killall, WITH_ANSWER, TVOID(result), TINT(reset_pid)) sep \
 -ACTION(SIMCALL_PROCESS_CLEANUP, process_cleanup, WITH_ANSWER, TVOID(result), TSPEC(process, smx_process_t)) sep \
 -ACTION(SIMCALL_PROCESS_CHANGE_HOST, process_change_host, WITH_ANSWER, TVOID(result), TSPEC(process, smx_process_t), TSPEC(dest, smx_host_t)) sep \
 -ACTION(SIMCALL_PROCESS_SUSPEND, process_suspend, WITHOUT_ANSWER, TVOID(result), TSPEC(process, smx_process_t)) sep \
 -ACTION(SIMCALL_PROCESS_RESUME, process_resume, WITH_ANSWER, TVOID(result), TSPEC(process, smx_process_t)) sep \
 +ACTION(SIMCALL_PROCESS_CLEANUP, process_cleanup, WITH_ANSWER, TVOID(result), TDSPEC(process, smx_process_t)) sep \
 +ACTION(SIMCALL_PROCESS_CHANGE_HOST, process_change_host, WITH_ANSWER, TVOID(result), TDSPEC(process, smx_process_t), TDSPEC(dest, smx_host_t)) sep \
 +ACTION(SIMCALL_PROCESS_SUSPEND, process_suspend, WITHOUT_ANSWER, TVOID(result), TDSPEC(process, smx_process_t)) sep \
 +ACTION(SIMCALL_PROCESS_RESUME, process_resume, WITH_ANSWER, TVOID(result), TDSPEC(process, smx_process_t)) sep \
  ACTION(SIMCALL_PROCESS_COUNT, process_count, WITH_ANSWER, TINT(result)) sep \
 -ACTION(SIMCALL_PROCESS_GET_PID, process_get_PID, WITH_ANSWER, TINT(result), TSPEC(process, smx_process_t)) sep  \
 -ACTION(SIMCALL_PROCESS_GET_PPID, process_get_PPID, WITH_ANSWER, TINT(result), TSPEC(process, smx_process_t)) sep  \
 -ACTION(SIMCALL_PROCESS_GET_DATA, process_get_data, WITH_ANSWER, TPTR(result), TSPEC(process, smx_process_t)) sep \
 -ACTION(SIMCALL_PROCESS_SET_DATA, process_set_data, WITH_ANSWER, TVOID(result), TSPEC(process, smx_process_t), TPTR(data)) sep \
 -ACTION(SIMCALL_PROCESS_GET_HOST, process_get_host, WITH_ANSWER, TSPEC(result, smx_host_t), TSPEC(process, smx_process_t)) sep \
 -ACTION(SIMCALL_PROCESS_GET_NAME, process_get_name, WITH_ANSWER, TSTRING(result), TSPEC(process, smx_process_t)) sep \
 -ACTION(SIMCALL_PROCESS_IS_SUSPENDED, process_is_suspended, WITH_ANSWER, TINT(result), TSPEC(process, smx_process_t)) sep \
 -ACTION(SIMCALL_PROCESS_GET_PROPERTIES, process_get_properties, WITH_ANSWER, TSPEC(result, xbt_dict_t), TSPEC(process, smx_process_t)) sep \
 +ACTION(SIMCALL_PROCESS_GET_PID, process_get_PID, WITH_ANSWER, TINT(result), TDSPEC(process, smx_process_t)) sep  \
 +ACTION(SIMCALL_PROCESS_GET_PPID, process_get_PPID, WITH_ANSWER, TINT(result), TDSPEC(process, smx_process_t)) sep  \
 +ACTION(SIMCALL_PROCESS_GET_DATA, process_get_data, WITH_ANSWER, TDPTR(result), TDSPEC(process, smx_process_t)) sep \
 +ACTION(SIMCALL_PROCESS_SET_DATA, process_set_data, WITH_ANSWER, TVOID(result), TDSPEC(process, smx_process_t), TDPTR(data)) sep \
 +ACTION(SIMCALL_PROCESS_GET_HOST, process_get_host, WITH_ANSWER, TDSPEC(result, smx_host_t), TDSPEC(process, smx_process_t)) sep \
 +ACTION(SIMCALL_PROCESS_GET_NAME, process_get_name, WITH_ANSWER, TSTRING(result), TDSPEC(process, smx_process_t)) sep \
 +ACTION(SIMCALL_PROCESS_IS_SUSPENDED, process_is_suspended, WITH_ANSWER, TINT(result), TDSPEC(process, smx_process_t)) sep \
 +ACTION(SIMCALL_PROCESS_GET_PROPERTIES, process_get_properties, WITH_ANSWER, TDSPEC(result, xbt_dict_t), TDSPEC(process, smx_process_t)) sep \
  ACTION(SIMCALL_PROCESS_SLEEP, process_sleep, WITHOUT_ANSWER, TINT(result), TDOUBLE(duration)) sep \
 -ACTION(SIMCALL_PROCESS_ON_EXIT, process_on_exit, WITH_ANSWER, TVOID(result), TSPEC(process, smx_process_t), TSPEC(fun, int_f_pvoid_t), TPTR(data)) sep \
 -ACTION(SIMCALL_PROCESS_AUTO_RESTART_SET, process_auto_restart_set, WITH_ANSWER, TVOID(result), TSPEC(process, smx_process_t), TINT(auto_restart)) sep \
 -ACTION(SIMCALL_PROCESS_RESTART, process_restart, WITH_ANSWER, TSPEC(result, smx_process_t), TSPEC(process, smx_process_t)) sep \
 -ACTION(SIMCALL_RDV_CREATE, rdv_create, WITH_ANSWER, TSPEC(result, smx_rdv_t), TSTRING(name)) sep \
 -ACTION(SIMCALL_RDV_DESTROY, rdv_destroy, WITH_ANSWER, TVOID(result), TSPEC(rdv, smx_rdv_t)) sep \
 -ACTION(SIMCALL_RDV_GET_BY_NAME, rdv_get_by_name, WITH_ANSWER, TSPEC(result, smx_host_t), TSTRING(name)) sep \
 -ACTION(SIMCALL_RDV_COMM_COUNT_BY_HOST, rdv_comm_count_by_host, WITH_ANSWER, TUINT(result), TSPEC(rdv, smx_rdv_t), TSPEC(host, smx_host_t)) sep \
 -ACTION(SIMCALL_RDV_GET_HEAD, rdv_get_head, WITH_ANSWER, TSPEC(result, smx_action_t), TSPEC(rdv, smx_rdv_t)) sep \
 -ACTION(SIMCALL_RDV_SET_RECV, rdv_set_receiver, WITH_ANSWER, TVOID(result), TSPEC(rdv, smx_rdv_t), TSPEC(receiver, smx_process_t)) sep \
 -ACTION(SIMCALL_RDV_GET_RECV, rdv_get_receiver, WITH_ANSWER, TSPEC(result, smx_process_t), TSPEC(rdv, smx_rdv_t)) sep \
 -ACTION(SIMCALL_COMM_IPROBE, comm_iprobe, WITH_ANSWER, TSPEC(result, smx_action_t), TSPEC(rdv, smx_rdv_t), TINT(src), TINT(tag), TSPEC(match_fun, simix_match_func_t), TPTR(data)) sep \
 -ACTION(SIMCALL_COMM_SEND, comm_send, WITHOUT_ANSWER, TVOID(result), TSPEC(rdv, smx_rdv_t), TDOUBLE(task_size), TDOUBLE(rate), TPTR(src_buff), TSIZE(src_buff_size), TSPEC(match_fun, simix_match_func_t), TPTR(data), TDOUBLE(timeout)) sep \
 -ACTION(SIMCALL_COMM_ISEND, comm_isend, WITH_ANSWER, TSPEC(result, smx_action_t), TSPEC(rdv, smx_rdv_t), TDOUBLE(task_size), TDOUBLE(rate), TPTR(src_buff), TSIZE(src_buff_size), TSPEC(match_fun, simix_match_func_t), TSPEC(clean_fun, simix_clean_func_t), TPTR(data), TINT(detached)) sep \
 -ACTION(SIMCALL_COMM_RECV, comm_recv, WITHOUT_ANSWER, TVOID(result), TSPEC(rdv, smx_rdv_t), TPTR(dst_buff), TSPEC(dst_buff_size, size_t*), TSPEC(match_fun, simix_match_func_t), TPTR(data), TDOUBLE(timeout)) sep \
 -ACTION(SIMCALL_COMM_IRECV, comm_irecv, WITH_ANSWER, TSPEC(result, smx_action_t), TSPEC(rdv, smx_rdv_t), TPTR(dst_buff), TSPEC(dst_buff_size, size_t*), TSPEC(match_fun, simix_match_func_t), TPTR(data)) sep \
 -ACTION(SIMCALL_COMM_RECV_BOUNDED, comm_recv_bounded, WITHOUT_ANSWER, TVOID(result), TSPEC(rdv, smx_rdv_t), TPTR(dst_buff), TSPEC(dst_buff_size, size_t*), TSPEC(match_fun, simix_match_func_t), TPTR(data), TDOUBLE(timeout), TDOUBLE(rate)) sep \
 -ACTION(SIMCALL_COMM_IRECV_BOUNDED, comm_irecv_bounded, WITH_ANSWER, TSPEC(result, smx_action_t), TSPEC(rdv, smx_rdv_t), TPTR(dst_buff), TSPEC(dst_buff_size, size_t*), TSPEC(match_fun, simix_match_func_t), TPTR(data), TDOUBLE(rate)) sep \
 -ACTION(SIMCALL_COMM_DESTROY, comm_destroy, WITH_ANSWER, TVOID(result), TSPEC(comm, smx_action_t)) sep \
 -ACTION(SIMCALL_COMM_CANCEL, comm_cancel, WITH_ANSWER, TVOID(result), TSPEC(comm, smx_action_t)) sep \
 -ACTION(SIMCALL_COMM_WAITANY, comm_waitany, WITHOUT_ANSWER, TINT(result), TSPEC(comms, xbt_dynar_t)) sep \
 -ACTION(SIMCALL_COMM_WAIT, comm_wait, WITHOUT_ANSWER, TVOID(result), TSPEC(comm, smx_action_t), TDOUBLE(timeout)) sep \
 -ACTION(SIMCALL_COMM_TEST, comm_test, WITHOUT_ANSWER, TINT(result), TSPEC(comm, smx_action_t)) sep \
 -ACTION(SIMCALL_COMM_TESTANY, comm_testany, WITHOUT_ANSWER, TINT(result), TSPEC(comms, xbt_dynar_t)) sep \
 -ACTION(SIMCALL_COMM_GET_REMAINS, comm_get_remains, WITH_ANSWER, TDOUBLE(result), TSPEC(comm, smx_action_t)) sep \
 -ACTION(SIMCALL_COMM_GET_STATE, comm_get_state, WITH_ANSWER, TINT(result), TSPEC(comm, smx_action_t)) sep \
 -ACTION(SIMCALL_COMM_GET_SRC_DATA, comm_get_src_data, WITH_ANSWER, TPTR(result), TSPEC(comm, smx_action_t)) sep \
 -ACTION(SIMCALL_COMM_GET_DST_DATA, comm_get_dst_data, WITH_ANSWER, TPTR(result), TSPEC(comm, smx_action_t)) sep \
 -ACTION(SIMCALL_COMM_GET_SRC_PROC, comm_get_src_proc, WITH_ANSWER, TSPEC(result, smx_process_t), TSPEC(comm, smx_action_t)) sep \
 -ACTION(SIMCALL_COMM_GET_DST_PROC, comm_get_dst_proc, WITH_ANSWER, TSPEC(result, smx_process_t), TSPEC(comm, smx_action_t)) sep \
 -ACTION(SIMCALL_MUTEX_INIT, mutex_init, WITH_ANSWER, TSPEC(result, smx_mutex_t)) sep \
 -ACTION(SIMCALL_MUTEX_DESTROY, mutex_destroy, WITH_ANSWER, TVOID(result), TSPEC(mutex, smx_mutex_t)) sep \
 -ACTION(SIMCALL_MUTEX_LOCK, mutex_lock, WITHOUT_ANSWER, TVOID(result), TSPEC(mutex, smx_mutex_t)) sep \
 -ACTION(SIMCALL_MUTEX_TRYLOCK, mutex_trylock, WITH_ANSWER, TINT(result), TSPEC(mutex, smx_mutex_t)) sep \
 -ACTION(SIMCALL_MUTEX_UNLOCK, mutex_unlock, WITH_ANSWER, TVOID(result), TSPEC(mutex, smx_mutex_t)) sep \
 -ACTION(SIMCALL_COND_INIT, cond_init, WITH_ANSWER, TSPEC(result, smx_cond_t)) sep \
 -ACTION(SIMCALL_COND_DESTROY, cond_destroy, WITH_ANSWER, TVOID(result), TSPEC(cond, smx_cond_t)) sep \
 -ACTION(SIMCALL_COND_SIGNAL, cond_signal, WITH_ANSWER, TVOID(result), TSPEC(cond, smx_cond_t)) sep \
 -ACTION(SIMCALL_COND_WAIT, cond_wait, WITHOUT_ANSWER, TVOID(result), TSPEC(cond, smx_cond_t), TSPEC(mutex, smx_mutex_t)) sep \
 -ACTION(SIMCALL_COND_WAIT_TIMEOUT, cond_wait_timeout, WITHOUT_ANSWER, TVOID(result), TSPEC(cond, smx_cond_t), TSPEC(mutex, smx_mutex_t), TDOUBLE(timeout)) sep \
 -ACTION(SIMCALL_COND_BROADCAST, cond_broadcast, WITH_ANSWER, TVOID(result), TSPEC(cond, smx_cond_t)) sep \
 -ACTION(SIMCALL_SEM_INIT, sem_init, WITH_ANSWER, TSPEC(result, smx_sem_t), TINT(capacity)) sep \
 -ACTION(SIMCALL_SEM_DESTROY, sem_destroy, WITH_ANSWER, TVOID(result), TSPEC(sem, smx_sem_t)) sep \
 -ACTION(SIMCALL_SEM_RELEASE, sem_release, WITH_ANSWER, TVOID(result), TSPEC(sem, smx_sem_t)) sep \
 -ACTION(SIMCALL_SEM_WOULD_BLOCK, sem_would_block, WITH_ANSWER, TINT(result), TSPEC(sem, smx_sem_t)) sep \
 -ACTION(SIMCALL_SEM_ACQUIRE, sem_acquire, WITHOUT_ANSWER, TVOID(result), TSPEC(sem, smx_sem_t)) sep \
 -ACTION(SIMCALL_SEM_ACQUIRE_TIMEOUT, sem_acquire_timeout, WITHOUT_ANSWER, TVOID(result), TSPEC(sem, smx_sem_t), TDOUBLE(timeout)) sep \
 -ACTION(SIMCALL_SEM_GET_CAPACITY, sem_get_capacity, WITH_ANSWER, TINT(result), TSPEC(sem, smx_sem_t)) sep \
 -ACTION(SIMCALL_FILE_GET_DATA, file_get_data, WITH_ANSWER, TPTR(result), TSPEC(fd, smx_file_t)) sep \
 -ACTION(SIMCALL_FILE_SET_DATA, file_set_data, WITH_ANSWER, TVOID(result), TSPEC(fd, smx_file_t), TPTR(data)) sep \
 -ACTION(SIMCALL_FILE_READ, file_read, WITHOUT_ANSWER, TSIZE(result), TSPEC(fd, smx_file_t), TSIZE(size)) sep \
 -ACTION(SIMCALL_FILE_WRITE, file_write, WITHOUT_ANSWER, TSIZE(result), TSPEC(fd, smx_file_t), TSIZE(size)) sep \
 -ACTION(SIMCALL_FILE_OPEN, file_open, WITHOUT_ANSWER, TSPEC(result, smx_file_t), TSTRING(mount), TSTRING(path)) sep \
 -ACTION(SIMCALL_FILE_CLOSE, file_close, WITHOUT_ANSWER, TINT(result), TSPEC(fd, smx_file_t)) sep \
 -ACTION(SIMCALL_FILE_UNLINK, file_unlink, WITH_ANSWER, TINT(result), TSPEC(fd, smx_file_t)) sep \
 -ACTION(SIMCALL_FILE_LS, file_ls, WITHOUT_ANSWER, TSPEC(result, xbt_dict_t), TSTRING(mount), TSTRING(path)) sep \
 -ACTION(SIMCALL_FILE_GET_SIZE, file_get_size, WITH_ANSWER, TSIZE(result), TSPEC(fd, smx_file_t)) sep \
 -ACTION(SIMCALL_FILE_GET_INFO, file_get_info, WITH_ANSWER, TSPEC(result, xbt_dynar_t), TSPEC(fd, smx_file_t)) sep \
 +ACTION(SIMCALL_PROCESS_ON_EXIT, process_on_exit, WITH_ANSWER, TVOID(result), TDSPEC(process, smx_process_t), TFSPEC(fun, int_f_pvoid_t), TDPTR(data)) sep \
 +ACTION(SIMCALL_PROCESS_AUTO_RESTART_SET, process_auto_restart_set, WITH_ANSWER, TVOID(result), TDSPEC(process, smx_process_t), TINT(auto_restart)) sep \
 +ACTION(SIMCALL_PROCESS_RESTART, process_restart, WITH_ANSWER, TDSPEC(result, smx_process_t), TDSPEC(process, smx_process_t)) sep \
 +ACTION(SIMCALL_RDV_CREATE, rdv_create, WITH_ANSWER, TDSPEC(result, smx_rdv_t), TSTRING(name)) sep \
 +ACTION(SIMCALL_RDV_DESTROY, rdv_destroy, WITH_ANSWER, TVOID(result), TDSPEC(rdv, smx_rdv_t)) sep \
 +ACTION(SIMCALL_RDV_GET_BY_NAME, rdv_get_by_name, WITH_ANSWER, TDSPEC(result, smx_host_t), TSTRING(name)) sep \
 +ACTION(SIMCALL_RDV_COMM_COUNT_BY_HOST, rdv_comm_count_by_host, WITH_ANSWER, TUINT(result), TDSPEC(rdv, smx_rdv_t), TDSPEC(host, smx_host_t)) sep \
 +ACTION(SIMCALL_RDV_GET_HEAD, rdv_get_head, WITH_ANSWER, TDSPEC(result, smx_action_t), TDSPEC(rdv, smx_rdv_t)) sep \
 +ACTION(SIMCALL_RDV_SET_RECV, rdv_set_receiver, WITH_ANSWER, TVOID(result), TDSPEC(rdv, smx_rdv_t), TDSPEC(receiver, smx_process_t)) sep \
 +ACTION(SIMCALL_RDV_GET_RECV, rdv_get_receiver, WITH_ANSWER, TDSPEC(result, smx_process_t), TDSPEC(rdv, smx_rdv_t)) sep \
 +ACTION(SIMCALL_COMM_IPROBE, comm_iprobe, WITH_ANSWER, TDSPEC(result, smx_action_t), TDSPEC(rdv, smx_rdv_t), TINT(src), TINT(tag), TFSPEC(match_fun, simix_match_func_t), TDPTR(data)) sep \
 +ACTION(SIMCALL_COMM_SEND, comm_send, WITHOUT_ANSWER, TVOID(result), TDSPEC(rdv, smx_rdv_t), TDOUBLE(task_size), TDOUBLE(rate), TDPTR(src_buff), TSIZE(src_buff_size), TFSPEC(match_fun, simix_match_func_t), TDPTR(data), TDOUBLE(timeout)) sep \
 +ACTION(SIMCALL_COMM_ISEND, comm_isend, WITH_ANSWER, TDSPEC(result, smx_action_t), TDSPEC(rdv, smx_rdv_t), TDOUBLE(task_size), TDOUBLE(rate), TDPTR(src_buff), TSIZE(src_buff_size), TFSPEC(match_fun, simix_match_func_t), TFSPEC(clean_fun, simix_clean_func_t), TDPTR(data), TINT(detached)) sep \
 +ACTION(SIMCALL_COMM_RECV, comm_recv, WITHOUT_ANSWER, TVOID(result), TDSPEC(rdv, smx_rdv_t), TDPTR(dst_buff), TDSPEC(dst_buff_size, size_t*), TFSPEC(match_fun, simix_match_func_t), TDPTR(data), TDOUBLE(timeout)) sep \
 +ACTION(SIMCALL_COMM_IRECV, comm_irecv, WITH_ANSWER, TDSPEC(result, smx_action_t), TDSPEC(rdv, smx_rdv_t), TDPTR(dst_buff), TDSPEC(dst_buff_size, size_t*), TFSPEC(match_fun, simix_match_func_t), TDPTR(data)) sep \
 +ACTION(SIMCALL_COMM_RECV_BOUNDED, comm_recv_bounded, WITHOUT_ANSWER, TVOID(result), TDSPEC(rdv, smx_rdv_t), TDPTR(dst_buff), TDSPEC(dst_buff_size, size_t*), TFSPEC(match_fun, simix_match_func_t), TDPTR(data), TDOUBLE(timeout), TDOUBLE(rate)) sep \
 +ACTION(SIMCALL_COMM_IRECV_BOUNDED, comm_irecv_bounded, WITH_ANSWER, TDSPEC(result, smx_action_t), TDSPEC(rdv, smx_rdv_t), TDPTR(dst_buff), TDSPEC(dst_buff_size, size_t*), TFSPEC(match_fun, simix_match_func_t), TDPTR(data), TDOUBLE(rate)) sep \
 +ACTION(SIMCALL_COMM_DESTROY, comm_destroy, WITH_ANSWER, TVOID(result), TDSPEC(comm, smx_action_t)) sep \
 +ACTION(SIMCALL_COMM_CANCEL, comm_cancel, WITH_ANSWER, TVOID(result), TDSPEC(comm, smx_action_t)) sep \
 +ACTION(SIMCALL_COMM_WAITANY, comm_waitany, WITHOUT_ANSWER, TINT(result), TDSPEC(comms, xbt_dynar_t)) sep \
 +ACTION(SIMCALL_COMM_WAIT, comm_wait, WITHOUT_ANSWER, TVOID(result), TDSPEC(comm, smx_action_t), TDOUBLE(timeout)) sep \
 +ACTION(SIMCALL_COMM_TEST, comm_test, WITHOUT_ANSWER, TINT(result), TDSPEC(comm, smx_action_t)) sep \
 +ACTION(SIMCALL_COMM_TESTANY, comm_testany, WITHOUT_ANSWER, TINT(result), TDSPEC(comms, xbt_dynar_t)) sep \
 +ACTION(SIMCALL_COMM_GET_REMAINS, comm_get_remains, WITH_ANSWER, TDOUBLE(result), TDSPEC(comm, smx_action_t)) sep \
 +ACTION(SIMCALL_COMM_GET_STATE, comm_get_state, WITH_ANSWER, TINT(result), TDSPEC(comm, smx_action_t)) sep \
 +ACTION(SIMCALL_COMM_GET_SRC_DATA, comm_get_src_data, WITH_ANSWER, TDPTR(result), TDSPEC(comm, smx_action_t)) sep \
 +ACTION(SIMCALL_COMM_GET_DST_DATA, comm_get_dst_data, WITH_ANSWER, TDPTR(result), TDSPEC(comm, smx_action_t)) sep \
 +ACTION(SIMCALL_COMM_GET_SRC_PROC, comm_get_src_proc, WITH_ANSWER, TDSPEC(result, smx_process_t), TDSPEC(comm, smx_action_t)) sep \
 +ACTION(SIMCALL_COMM_GET_DST_PROC, comm_get_dst_proc, WITH_ANSWER, TDSPEC(result, smx_process_t), TDSPEC(comm, smx_action_t)) sep \
 +ACTION(SIMCALL_MUTEX_INIT, mutex_init, WITH_ANSWER, TDSPEC(result, smx_mutex_t)) sep \
 +ACTION(SIMCALL_MUTEX_DESTROY, mutex_destroy, WITH_ANSWER, TVOID(result), TDSPEC(mutex, smx_mutex_t)) sep \
 +ACTION(SIMCALL_MUTEX_LOCK, mutex_lock, WITHOUT_ANSWER, TVOID(result), TDSPEC(mutex, smx_mutex_t)) sep \
 +ACTION(SIMCALL_MUTEX_TRYLOCK, mutex_trylock, WITH_ANSWER, TINT(result), TDSPEC(mutex, smx_mutex_t)) sep \
 +ACTION(SIMCALL_MUTEX_UNLOCK, mutex_unlock, WITH_ANSWER, TVOID(result), TDSPEC(mutex, smx_mutex_t)) sep \
 +ACTION(SIMCALL_COND_INIT, cond_init, WITH_ANSWER, TDSPEC(result, smx_cond_t)) sep \
 +ACTION(SIMCALL_COND_DESTROY, cond_destroy, WITH_ANSWER, TVOID(result), TDSPEC(cond, smx_cond_t)) sep \
 +ACTION(SIMCALL_COND_SIGNAL, cond_signal, WITH_ANSWER, TVOID(result), TDSPEC(cond, smx_cond_t)) sep \
 +ACTION(SIMCALL_COND_WAIT, cond_wait, WITHOUT_ANSWER, TVOID(result), TDSPEC(cond, smx_cond_t), TDSPEC(mutex, smx_mutex_t)) sep \
 +ACTION(SIMCALL_COND_WAIT_TIMEOUT, cond_wait_timeout, WITHOUT_ANSWER, TVOID(result), TDSPEC(cond, smx_cond_t), TDSPEC(mutex, smx_mutex_t), TDOUBLE(timeout)) sep \
 +ACTION(SIMCALL_COND_BROADCAST, cond_broadcast, WITH_ANSWER, TVOID(result), TDSPEC(cond, smx_cond_t)) sep \
 +ACTION(SIMCALL_SEM_INIT, sem_init, WITH_ANSWER, TDSPEC(result, smx_sem_t), TINT(capacity)) sep \
 +ACTION(SIMCALL_SEM_DESTROY, sem_destroy, WITH_ANSWER, TVOID(result), TDSPEC(sem, smx_sem_t)) sep \
 +ACTION(SIMCALL_SEM_RELEASE, sem_release, WITH_ANSWER, TVOID(result), TDSPEC(sem, smx_sem_t)) sep \
 +ACTION(SIMCALL_SEM_WOULD_BLOCK, sem_would_block, WITH_ANSWER, TINT(result), TDSPEC(sem, smx_sem_t)) sep \
 +ACTION(SIMCALL_SEM_ACQUIRE, sem_acquire, WITHOUT_ANSWER, TVOID(result), TDSPEC(sem, smx_sem_t)) sep \
 +ACTION(SIMCALL_SEM_ACQUIRE_TIMEOUT, sem_acquire_timeout, WITHOUT_ANSWER, TVOID(result), TDSPEC(sem, smx_sem_t), TDOUBLE(timeout)) sep \
 +ACTION(SIMCALL_SEM_GET_CAPACITY, sem_get_capacity, WITH_ANSWER, TINT(result), TDSPEC(sem, smx_sem_t)) sep \
- ACTION(SIMCALL_FILE_READ, file_read, WITHOUT_ANSWER, TSIZE(result), TDPTR(ptr), TSIZE(size), TDSPEC(fd, smx_file_t)) sep \
- ACTION(SIMCALL_FILE_WRITE, file_write, WITHOUT_ANSWER, TSIZE(result), TCPTR(ptr), TSIZE(size), TDSPEC(fd, smx_file_t)) sep \
++ACTION(SIMCALL_FILE_GET_DATA, file_get_data, WITH_ANSWER, TDPTR(result), TDSPEC(fd, smx_file_t)) sep \
++ACTION(SIMCALL_FILE_SET_DATA, file_set_data, WITH_ANSWER, TVOID(result), TDSPEC(fd, smx_file_t), TDPTR(data)) sep \
++ACTION(SIMCALL_FILE_READ, file_read, WITHOUT_ANSWER, TSIZE(result), TDSPEC(fd, smx_file_t),  TSIZE(size)) sep \
++ACTION(SIMCALL_FILE_WRITE, file_write, WITHOUT_ANSWER, TSIZE(result), TDSPEC(fd, smx_file_t), TSIZE(size)) sep \
 +ACTION(SIMCALL_FILE_OPEN, file_open, WITHOUT_ANSWER, TDSPEC(result, smx_file_t), TSTRING(mount), TSTRING(path)) sep \
 +ACTION(SIMCALL_FILE_CLOSE, file_close, WITHOUT_ANSWER, TINT(result), TDSPEC(fd, smx_file_t)) sep \
 +ACTION(SIMCALL_FILE_UNLINK, file_unlink, WITH_ANSWER, TINT(result), TDSPEC(fd, smx_file_t)) sep \
 +ACTION(SIMCALL_FILE_LS, file_ls, WITHOUT_ANSWER, TDSPEC(result, xbt_dict_t), TSTRING(mount), TSTRING(path)) sep \
 +ACTION(SIMCALL_FILE_GET_SIZE, file_get_size, WITH_ANSWER, TSIZE(result), TDSPEC(fd, smx_file_t)) sep \
- ACTION(SIMCALL_ASR_GET_PROPERTIES, asr_get_properties, WITH_ANSWER, TDSPEC(result, xbt_dict_t), TSTRING(name)) sep 
++ACTION(SIMCALL_FILE_GET_INFO, file_get_info, WITH_ANSWER, TDSPEC(result, xbt_dynar_t), TDSPEC(fd, smx_file_t)) sep \
+ ACTION(SIMCALL_STORAGE_GET_FREE_SIZE, storage_get_free_size, WITH_ANSWER, TSIZE(result), TSTRING(name)) sep \
+ ACTION(SIMCALL_STORAGE_GET_USED_SIZE, storage_get_used_size, WITH_ANSWER, TSIZE(result), TSTRING(name)) sep \
 -ACTION(SIMCALL_STORAGE_GET_PROPERTIES, storage_get_properties, WITH_ANSWER, TSPEC(result, xbt_dict_t), TSPEC(storage, smx_storage_t)) sep \
 -ACTION(SIMCALL_STORAGE_GET_CONTENT, storage_get_content, WITH_ANSWER, TSPEC(result, xbt_dict_t), TSPEC(storage, smx_storage_t)) sep \
 -ACTION(SIMCALL_ASR_GET_PROPERTIES, asr_get_properties, WITH_ANSWER, TSPEC(result, xbt_dict_t), TSTRING(name)) sep 
++ACTION(SIMCALL_STORAGE_GET_PROPERTIES, storage_get_properties, WITH_ANSWER, TDSPEC(result, xbt_dict_t), TDSPEC(storage, smx_storage_t)) sep \
++ACTION(SIMCALL_STORAGE_GET_CONTENT, storage_get_content, WITH_ANSWER, TDSPEC(result, xbt_dict_t), TDSPEC(storage, smx_storage_t)) sep \
++ACTION(SIMCALL_ASR_GET_PROPERTIES, asr_get_properties, WITH_ANSWER, TDSPEC(result, xbt_dict_t), TSTRING(name)) sep
  
  /* SIMCALL_COMM_IS_LATENCY_BOUNDED and SIMCALL_SET_CATEGORY make things complicated
   * because they are not always present */
  #ifdef HAVE_LATENCY_BOUND_TRACKING
  #define SIMCALL_LIST2(ACTION, sep) \
 -ACTION(SIMCALL_COMM_IS_LATENCY_BOUNDED, comm_is_latency_bounded, WITH_ANSWER, TINT(result), TSPEC(comm, smx_action_t)) sep
 +ACTION(SIMCALL_COMM_IS_LATENCY_BOUNDED, comm_is_latency_bounded, WITH_ANSWER, TINT(result), TDSPEC(comm, smx_action_t)) sep
  #else
  #define SIMCALL_LIST2(ACTION, sep)
  #endif
  
  #ifdef HAVE_TRACING
  #define SIMCALL_LIST3(ACTION, sep) \
 -ACTION(SIMCALL_SET_CATEGORY, set_category, WITH_ANSWER, TVOID(result), TSPEC(action, smx_action_t), TSTRING(category)) sep
 +ACTION(SIMCALL_SET_CATEGORY, set_category, WITH_ANSWER, TVOID(result), TDSPEC(action, smx_action_t), TSTRING(category)) sep
  #else
  #define SIMCALL_LIST3(ACTION, sep)
  #endif
  
  #ifdef HAVE_MC
  #define SIMCALL_LIST4(ACTION, sep) \
 -ACTION(SIMCALL_MC_SNAPSHOT, mc_snapshot, WITH_ANSWER, TPTR(result)) sep \
 -ACTION(SIMCALL_MC_COMPARE_SNAPSHOTS, mc_compare_snapshots, WITH_ANSWER, TINT(result), TPTR(s1), TPTR(s2)) sep \
 +ACTION(SIMCALL_MC_SNAPSHOT, mc_snapshot, WITH_ANSWER, TDPTR(result)) sep \
 +ACTION(SIMCALL_MC_COMPARE_SNAPSHOTS, mc_compare_snapshots, WITH_ANSWER, TINT(result), TDPTR(s1), TDPTR(s2)) sep \
- ACTION(SIMCALL_MC_RANDOM, mc_random, WITH_ANSWER, TINT(result)) sep
+ ACTION(SIMCALL_MC_RANDOM, mc_random, WITH_ANSWER, TINT(result), TINT(min), TINT(max)) sep
  #else
  #define SIMCALL_LIST4(ACTION, sep)
  #endif
@@@ -412,7 -412,6 +426,7 @@@ NUM_SIMCALL
  
  typedef int (*simix_match_func_t)(void *, void *, smx_action_t);
  typedef void (*simix_clean_func_t)(void *);
 +typedef void (*FPtr)(void); // Hide the ugliness
  
  /* Pack all possible scalar types in an union */
  union u_smx_scalar {
    float           f;
    double          d;
    size_t          si;
 -  void*           p;
 +  void*           dp;
 +  FPtr            fp;
    const void*     cp;
  };
  
@@@ -453,14 -451,8 +467,14 @@@ typedef struct s_smx_simcall 
    };
  } s_smx_simcall_t, *smx_simcall_t;
  
 +#ifdef __cplusplus
 +extern "C" {
 +#endif
  SIMCALL_LIST(SIMCALL_RES_GETSET, SIMCALL_SEP_NOTHING)
  SIMCALL_LIST(SIMCALL_ARG_GETSET, SIMCALL_SEP_NOTHING)
 +#ifdef __cplusplus
 +}
 +#endif
  
  /******************************** General *************************************/
  
diff --combined src/simix/smx_synchro.c
@@@ -1,4 -1,4 +1,4 @@@
- /* Copyright (c) 2007, 2008, 2009, 2010. The SimGrid Team.
+ /* Copyright (c) 2007-2013. The SimGrid Team.
   * All rights reserved.                                                     */
  
  /* This program is free software; you can redistribute it and/or modify it
@@@ -28,9 -28,9 +28,9 @@@ static smx_action_t SIMIX_synchro_wait(
    action->type = SIMIX_ACTION_SYNCHRO;
    action->name = xbt_strdup("synchro");
    action->synchro.sleep = 
 -    surf_workstation_model->extension.workstation.sleep(smx_host, timeout);
 +    surf_workstation_sleep(smx_host, timeout);
  
 -  surf_workstation_model->action_data_set(action->synchro.sleep, action);
 +  surf_action_set_data(action->synchro.sleep, action);
    XBT_OUT();
    return action;
  }
@@@ -70,7 -70,7 +70,7 @@@ void SIMIX_synchro_destroy(smx_action_
  {
    XBT_IN("(%p)",action);
    XBT_DEBUG("Destroying synchro %p", action);
 -  action->synchro.sleep->model_type->action_unref(action->synchro.sleep);
 +  surf_action_unref(action->synchro.sleep);
    xbt_free(action->name);
    xbt_mallocator_release(simix_global->action_mallocator, action);
    XBT_OUT();
@@@ -79,9 -79,9 +79,9 @@@
  void SIMIX_post_synchro(smx_action_t action)
  {
    XBT_IN("(%p)",action);
 -  if (surf_workstation_model->action_state_get(action->synchro.sleep) == SURF_ACTION_FAILED)
 +  if (surf_action_get_state(action->synchro.sleep) == SURF_ACTION_FAILED)
      action->state = SIMIX_FAILED;
 -  else if(surf_workstation_model->action_state_get(action->synchro.sleep) == SURF_ACTION_DONE)
 +  else if(surf_action_get_state(action->synchro.sleep) == SURF_ACTION_DONE)
      action->state = SIMIX_SRC_TIMEOUT;
  
    SIMIX_synchro_finish(action);  
@@@ -466,7 -466,7 +466,7 @@@ void SIMIX_sem_release(smx_sem_t sem
  }
  
  /** @brief Returns true if acquiring this semaphore would block */
XBT_INLINE int SIMIX_sem_would_block(smx_sem_t sem)
+ int SIMIX_sem_would_block(smx_sem_t sem)
  {
    XBT_IN("(%p)",sem);
    XBT_OUT();
diff --combined src/surf/cpu.cpp
index fe58cf0,0000000..d550b0a
mode 100644,000000..100644
--- /dev/null
@@@ -1,161 -1,0 +1,164 @@@
-   ActionLmmPtr action;
 +#include "cpu.hpp"
 +
 +extern "C" {
++XBT_LOG_EXTERNAL_CATEGORY(surf_kernel);
 +XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_cpu, surf,
 +                                "Logging specific to the SURF cpu module");
 +}
 +
 +CpuModelPtr surf_cpu_model;
 +
 +/*********
 + * Model *
 + *********/
 +
 +void CpuModel::updateActionsStateLazy(double now, double delta)
 +{
 +  void *_action;
-     action = (ActionLmmPtr) xbt_heap_pop(p_actionHeap);
-     XBT_DEBUG("Something happened to action %p", action);
++  CpuActionLmmPtr action;
 +  while ((xbt_heap_size(p_actionHeap) > 0)
 +         && (double_equals(xbt_heap_maxkey(p_actionHeap), now))) {
-     XBT_DEBUG("Action %p finished", action);
++    action = dynamic_cast<CpuActionLmmPtr>(static_cast<ActionLmmPtr>(xbt_heap_pop(p_actionHeap)));
++    XBT_CDEBUG(surf_kernel, "Something happened to action %p", action);
 +#ifdef HAVE_TRACING
 +    if (TRACE_is_enabled()) {
 +      CpuPtr cpu = (CpuPtr) lmm_constraint_id(lmm_get_cnst_from_var(p_maxminSystem, action->p_variable, 0));
 +      TRACE_surf_host_set_utilization(cpu->m_name, action->p_category,
 +                                      lmm_variable_getvalue(action->p_variable),
 +                                      action->m_lastUpdate,
 +                                      now - action->m_lastUpdate);
 +    }
 +#endif
 +
 +    action->m_finish = surf_get_clock();
-       action = dynamic_cast<ActionLmmPtr>(static_cast<ActionPtr>(_action));
++    XBT_CDEBUG(surf_kernel, "Action %p finished", action);
++
++    action->updateEnergy();
 +
 +    /* set the remains to 0 due to precision problems when updating the remaining amount */
 +    action->m_remains = 0;
 +    action->setState(SURF_ACTION_DONE);
 +    action->heapRemove(p_actionHeap); //FIXME: strange call since action was already popped
 +  }
 +#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)
 +    double smaller = -1;
 +    xbt_swag_foreach(_action, p_runningActionSet) {
-   ActionLmmPtr action = NULL;
-   ActionLmmPtr next_action = NULL;
++      action = dynamic_cast<CpuActionLmmPtr>(static_cast<ActionPtr>(_action));
 +        if (smaller < 0) {
 +          smaller = action->m_lastUpdate;
 +          continue;
 +        }
 +        if (action->m_lastUpdate < smaller) {
 +          smaller = action->m_lastUpdate;
 +        }
 +    }
 +    if (smaller > 0) {
 +      TRACE_last_timestamp_to_dump = smaller;
 +    }
 +  }
 +#endif
 +  return;
 +}
 +
 +void CpuModel::updateActionsStateFull(double now, double delta)
 +{
 +  void *_action, *_next_action;
-     action = dynamic_cast<ActionLmmPtr>(static_cast<ActionPtr>(_action));
++  CpuActionLmmPtr action = NULL;
 +  xbt_swag_t running_actions = p_runningActionSet;
 +
 +  xbt_swag_foreach_safe(_action, _next_action, running_actions) {
-     XBT_DEBUG("Updating action(%p): remains was %lf, last_update was: %lf", this, m_remains, m_lastUpdate);
++    action = dynamic_cast<CpuActionLmmPtr>(static_cast<ActionPtr>(_action));
 +#ifdef HAVE_TRACING
 +    if (TRACE_is_enabled()) {
 +      CpuPtr x = (CpuPtr) lmm_constraint_id(lmm_get_cnst_from_var
 +                              (p_maxminSystem, action->p_variable, 0));
 +
 +      TRACE_surf_host_set_utilization(x->m_name,
 +                                      action->p_category,
 +                                      lmm_variable_getvalue(action->p_variable),
 +                                      now - delta,
 +                                      delta);
 +      TRACE_last_timestamp_to_dump = now - delta;
 +    }
 +#endif
 +
 +    double_update(&(action->m_remains),
 +                  lmm_variable_getvalue(action->p_variable) * delta);
 +
 +
 +    if (action->m_maxDuration != NO_MAX_DURATION)
 +      double_update(&(action->m_maxDuration), delta);
 +
 +
 +    if ((action->m_remains <= 0) &&
 +        (lmm_get_variable_weight(action->p_variable) > 0)) {
 +      action->m_finish = surf_get_clock();
 +      action->setState(SURF_ACTION_DONE);
 +
 +    } else if ((action->m_maxDuration != NO_MAX_DURATION) &&
 +               (action->m_maxDuration <= 0)) {
 +      action->m_finish = surf_get_clock();
 +      action->setState(SURF_ACTION_DONE);
 +    }
++    action->updateEnergy();
 +  }
 +
 +  return;
 +}
 +
 +/************
 + * Resource *
 + ************/
 +
 +double Cpu::getSpeed(double load)
 +{
 +  return load * m_powerPeak;
 +}
 +
 +double Cpu::getAvailableSpeed()
 +{
 +/* number between 0 and 1 */
 +  return m_powerScale;
 +}
 +
 +int Cpu::getCore()
 +{
 +  return m_core;
 +}
 +
 +/**********
 + * Action *
 + **********/
 +
 +void CpuActionLmm::updateRemainingLazy(double now)
 +{
 +  double delta = 0.0;
 +
 +  xbt_assert(p_stateSet == p_model->p_runningActionSet,
 +      "You're updating an action that is not running.");
 +
 +  /* bogus priority, skip it */
 +  xbt_assert(m_priority > 0,
 +      "You're updating an action that seems suspended.");
 +
 +  delta = now - m_lastUpdate;
 +
 +  if (m_remains > 0) {
-     XBT_DEBUG("Updating action(%p): remains is now %lf", this, m_remains);
++    XBT_CDEBUG(surf_kernel, "Updating action(%p): remains was %lf, last_update was: %lf", this, m_remains, m_lastUpdate);
 +    double_update(&(m_remains), m_lastValue * delta);
 +
 +#ifdef HAVE_TRACING
 +    if (TRACE_is_enabled()) {
 +      CpuPtr cpu = (CpuPtr) lmm_constraint_id(lmm_get_cnst_from_var(p_model->p_maxminSystem, p_variable, 0));
 +      TRACE_surf_host_set_utilization(cpu->m_name, p_category, m_lastValue, m_lastUpdate, now - m_lastUpdate);
 +    }
 +#endif
++    XBT_CDEBUG(surf_kernel, "Updating action(%p): remains is now %lf", this, m_remains);
 +  }
 +
 +  m_lastUpdate = now;
 +  m_lastValue = lmm_variable_getvalue(p_variable);
 +}
diff --combined src/surf/cpu.hpp
index 5c69982,0000000..b7c5e78
mode 100644,000000..100644
--- /dev/null
@@@ -1,85 -1,0 +1,93 @@@
 +#include "surf.hpp"
 +
 +#ifndef SURF_MODEL_CPU_H_
 +#define SURF_MODEL_CPU_H_
 +
 +/***********
 + * Classes *
 + ***********/
 +class CpuModel;
 +typedef CpuModel *CpuModelPtr;
 +
 +class Cpu;
 +typedef Cpu *CpuPtr;
 +
 +class CpuLmm;
 +typedef CpuLmm *CpuLmmPtr;
 +
 +class CpuAction;
 +typedef CpuAction *CpuActionPtr;
 +
 +class CpuActionLmm;
 +typedef CpuActionLmm *CpuActionLmmPtr;
 +
 +/*********
 + * Model *
 + *********/
 +class CpuModel : public Model {
 +public:
 +  CpuModel(string name) : Model(name) {};
 +  CpuPtr createResource(string name);
 +  void updateActionsStateLazy(double now, double delta);
 +  void updateActionsStateFull(double now, double delta);
 +
 +  virtual void addTraces() =0;
 +};
 +
 +/************
 + * Resource *
 + ************/
 +class Cpu : virtual public Resource {
 +public:
 +  Cpu(){};
 +  Cpu(CpuModelPtr model, const char* name, xbt_dict_t properties) : Resource(model, name, properties) {};
 +  virtual ActionPtr execute(double size)=0;
 +  virtual ActionPtr sleep(double duration)=0;
 +  virtual int getCore();
 +  virtual double getSpeed(double load);
 +  virtual double getAvailableSpeed();
++
++  virtual double getCurrentPowerPeak()=0;
++  virtual double getPowerPeakAt(int pstate_index)=0;
++  virtual int getNbPstates()=0;
++  virtual void setPowerPeakAt(int pstate_index)=0;
++  virtual double getConsumedEnergy()=0;
++
 +  void addTraces(void);
 +  double m_powerPeak;            /*< CPU power peak */
 +  double m_powerScale;           /*< Percentage of CPU disponible */
 +protected:
 +  int m_core;
 +
 +  //virtual boost::shared_ptr<Action> execute(double size) = 0;
 +  //virtual boost::shared_ptr<Action> sleep(double duration) = 0;
 +};
 +
 +class CpuLmm : public ResourceLmm, public Cpu {
 +public:
 +  CpuLmm(){};
 +  CpuLmm(CpuModelPtr model, const char* name, xbt_dict_t properties) : ResourceLmm(), Cpu(model, name, properties) {};
 +
 +};
 +
 +/**********
 + * Action *
 + **********/
 +class CpuAction : virtual public Action {
 +public:
 +  CpuAction(){};
 +  CpuAction(ModelPtr model, double cost, bool failed)
 +  : Action(model, cost, failed) {};
 +};
 +
 +class CpuActionLmm : public ActionLmm, public CpuAction {
 +public:
 +  CpuActionLmm(){};
 +  CpuActionLmm(ModelPtr model, double cost, bool failed)
 +  : Action(model, cost, failed), ActionLmm(model, cost, failed), CpuAction(model, cost, failed) {};
 +  void updateRemainingLazy(double now);
++  virtual void updateEnergy()=0;
 +};
 +
 +
 +#endif /* SURF_MODEL_CPU_H_ */
diff --combined src/surf/cpu_cas01.cpp
index 6b5f1b8,0000000..61e1e9e
mode 100644,000000..100644
--- /dev/null
@@@ -1,337 -1,0 +1,505 @@@
- XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_cpu_cas, surf,
 +/* Copyright (c) 2009-2011. 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. */
 +
 +#include "cpu_cas01.hpp"
 +#include "cpu_ti.hpp"
 +#include "surf.hpp"
 +#include "maxmin_private.h"
 +#include "simgrid/sg_config.h"
 +
 +extern "C" {
- CpuCas01LmmPtr CpuCas01Model::createResource(const char *name, double power_peak, double power_scale,
++XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_cpu_cas, surf_cpu,
 +                                "Logging specific to the SURF CPU IMPROVED module");
 +}
 +
 +static xbt_swag_t
 +    cpu_running_action_set_that_does_not_need_being_checked = NULL;
 +
 +/*************
 + * CallBacks *
 + *************/
 +
 +static void parse_cpu_init(sg_platf_host_cbarg_t host){
 +  ((CpuCas01ModelPtr)surf_cpu_model)->parseInit(host);
 +}
 +
 +static void cpu_add_traces_cpu(){
 +  surf_cpu_model->addTraces();
 +}
 +
 +static void cpu_define_callbacks()
 +{
 +  sg_platf_host_add_cb(parse_cpu_init);
 +  sg_platf_postparse_add_cb(cpu_add_traces_cpu);
 +}
 +
 +/*********
 + * Model *
 + *********/
 +void surf_cpu_model_init_Cas01()
 +{
 +  char *optim = xbt_cfg_get_string(_sg_cfg_set, "cpu/optim");
 +
 +  if (surf_cpu_model)
 +    return;
 +
 +  if (!strcmp(optim, "TI")) {
 +    surf_cpu_model_init_ti();
 +    return;
 +  }
 +
 +  surf_cpu_model = new CpuCas01Model();
 +  cpu_define_callbacks();
 +  ModelPtr model = static_cast<ModelPtr>(surf_cpu_model);
 +  xbt_dynar_push(model_list, &model);
 +}
 +
 +CpuCas01Model::CpuCas01Model() : CpuModel("cpu")
 +{
 +  ActionPtr action;
 +  ActionLmmPtr actionlmm;
 +
 +  char *optim = xbt_cfg_get_string(_sg_cfg_set, "cpu/optim");
 +  int select = xbt_cfg_get_boolean(_sg_cfg_set, "cpu/maxmin_selective_update");
 +
 +  if (!strcmp(optim, "Full")) {
 +    p_updateMechanism = UM_FULL;
 +    m_selectiveUpdate = select;
 +  } else if (!strcmp(optim, "Lazy")) {
 +    p_updateMechanism = UM_LAZY;
 +    m_selectiveUpdate = 1;
 +    xbt_assert((select == 1)
 +               ||
 +               (xbt_cfg_is_default_value
 +                (_sg_cfg_set, "cpu/maxmin_selective_update")),
 +               "Disabling selective update while using the lazy update mechanism is dumb!");
 +  } else {
 +    xbt_die("Unsupported optimization (%s) for this model", optim);
 +  }
 +
 +  cpu_running_action_set_that_does_not_need_being_checked =
 +      xbt_swag_new(xbt_swag_offset(*action, p_stateHookup));
 +
 +  if (p_updateMechanism == UM_LAZY) {
 +      shareResources = &CpuCas01Model::shareResourcesLazy;
 +      updateActionsState = &CpuCas01Model::updateActionsStateLazy;
 +
 +  } else if (p_updateMechanism == UM_FULL) {
 +      shareResources = &CpuCas01Model::shareResourcesFull;
 +      updateActionsState = &CpuCas01Model::updateActionsStateFull;
 +  } else
 +    xbt_die("Invalid cpu update mechanism!");
 +
 +  if (!p_maxminSystem) {
 +    p_maxminSystem = lmm_system_new(m_selectiveUpdate);
 +  }
 +
 +  if (p_updateMechanism == UM_LAZY) {
 +    p_actionHeap = xbt_heap_new(8, NULL);
 +    xbt_heap_set_update_callback(p_actionHeap,  surf_action_lmm_update_index_heap);
 +    p_modifiedSet = xbt_swag_new(xbt_swag_offset(*actionlmm, p_actionListHookup));
 +    p_maxminSystem->keep_track = p_modifiedSet;
 +  }
 +}
 +
 +CpuCas01Model::~CpuCas01Model()
 +{
 +  lmm_system_free(p_maxminSystem);
 +  p_maxminSystem = NULL;
 +
 +  if (p_actionHeap)
 +    xbt_heap_free(p_actionHeap);
 +  xbt_swag_free(p_modifiedSet);
 +
 +  surf_cpu_model = NULL;
 +
 +  xbt_swag_free(cpu_running_action_set_that_does_not_need_being_checked);
 +  cpu_running_action_set_that_does_not_need_being_checked = NULL;
 +}
 +
 +void CpuCas01Model::parseInit(sg_platf_host_cbarg_t host)
 +{
 +  createResource(host->id,
 +        host->power_peak,
++        host->pstate,
 +        host->power_scale,
 +        host->power_trace,
 +        host->core_amount,
 +        host->initial_state,
 +        host->state_trace,
 +        host->properties);
 +}
 +
-   cpu = new CpuCas01Lmm(this, name, power_peak, power_scale, power_trace, core, state_initial, state_trace, cpu_properties);
++CpuCas01LmmPtr CpuCas01Model::createResource(const char *name, xbt_dynar_t power_peak,
++                                int pstate, double power_scale,
 +                          tmgr_trace_t power_trace, int core,
 +                          e_surf_resource_state_t state_initial,
 +                          tmgr_trace_t state_trace,
 +                          xbt_dict_t cpu_properties)
 +{
 +  CpuPtr cpu = NULL;
 +  xbt_assert(!surf_cpu_resource_priv(surf_cpu_resource_by_name(name)),
 +             "Host '%s' declared several times in the platform file",
 +             name);
 +  xbt_assert(power_peak > 0, "Power has to be >0");
 +  xbt_assert(core > 0, "Invalid number of cores %d", core);
 +
- CpuCas01Lmm::CpuCas01Lmm(CpuCas01ModelPtr model, const char *name, double powerPeak,
-         double powerScale, tmgr_trace_t powerTrace, int core,
++  cpu = new CpuCas01Lmm(this, name, power_peak, pstate, power_scale, power_trace, core, state_initial, state_trace, cpu_properties);
 +  xbt_lib_set(host_lib, name, SURF_CPU_LEVEL, static_cast<ResourcePtr>(cpu));
 +
 +  return (CpuCas01LmmPtr) xbt_lib_get_elm_or_null(host_lib, name);
 +}
 +
 +double CpuCas01Model::shareResourcesFull(double now)
 +{
 +  return Model::shareResourcesMaxMin(p_runningActionSet,
 +                             p_maxminSystem, lmm_solve);
 +}
 +
 +void CpuCas01Model::addTraces()
 +{
 +  xbt_dict_cursor_t cursor = NULL;
 +  char *trace_name, *elm;
 +  static int called = 0;
 +  if (called)
 +    return;
 +  called = 1;
 +
 +  /* connect all traces relative to hosts */
 +  xbt_dict_foreach(trace_connect_list_host_avail, cursor, trace_name, elm) {
 +    tmgr_trace_t trace = (tmgr_trace_t) xbt_dict_get_or_null(traces_set_list, trace_name);
 +    CpuCas01LmmPtr host = static_cast<CpuCas01LmmPtr>(surf_cpu_resource_priv(surf_cpu_resource_by_name(elm)));
 +
 +    xbt_assert(host, "Host %s undefined", elm);
 +    xbt_assert(trace, "Trace %s undefined", trace_name);
 +
 +    host->p_stateEvent =
 +        tmgr_history_add_trace(history, trace, 0.0, 0, static_cast<ResourcePtr>(host));
 +  }
 +
 +  xbt_dict_foreach(trace_connect_list_power, cursor, trace_name, elm) {
 +    tmgr_trace_t trace = (tmgr_trace_t) xbt_dict_get_or_null(traces_set_list, trace_name);
 +    CpuCas01LmmPtr host = dynamic_cast<CpuCas01LmmPtr>(static_cast<ResourcePtr>(surf_cpu_resource_priv(surf_cpu_resource_by_name(elm))));
 +
 +    xbt_assert(host, "Host %s undefined", elm);
 +    xbt_assert(trace, "Trace %s undefined", trace_name);
 +
 +    host->p_powerEvent =
 +        tmgr_history_add_trace(history, trace, 0.0, 0, static_cast<ResourcePtr>(host));
 +  }
 +}
 +
 +/************
 + * Resource *
 + ************/
-   m_powerPeak = powerPeak;
++CpuCas01Lmm::CpuCas01Lmm(CpuCas01ModelPtr model, const char *name, xbt_dynar_t powerPeak,
++              int pstate, double powerScale, tmgr_trace_t powerTrace, int core,
 +        e_surf_resource_state_t stateInitial, tmgr_trace_t stateTrace,
 +      xbt_dict_t properties) :
 +      CpuLmm(model, name, properties), Resource(model, name, properties) {
-   surf_watched_hosts();
++  m_powerPeak = xbt_dynar_get_as(powerPeak, pstate, double);
++  p_powerPeakList = powerPeak;
++  m_pstate = pstate;
++
++  p_energy = xbt_new(s_energy_cpu_cas01_t, 1);
++  p_energy->total_energy = 0;
++  p_energy->power_range_watts_list = getWattsRangeList();
++  p_energy->last_updated = surf_get_clock();
++
++  XBT_DEBUG("CPU create: peak=%f, pstate=%d", m_powerPeak, m_pstate);
++
 +  m_powerScale = powerScale;
 +  m_core = core;
 +  p_stateCurrent = stateInitial;
 +  if (powerTrace)
 +    p_powerEvent = tmgr_history_add_trace(history, powerTrace, 0.0, 0, static_cast<ResourcePtr>(this));
 +
 +  if (stateTrace)
 +    p_stateEvent = tmgr_history_add_trace(history, stateTrace, 0.0, 0, static_cast<ResourcePtr>(this));
 +
 +  p_constraint = lmm_constraint_new(p_model->p_maxminSystem, this, m_core * m_powerScale * m_powerPeak);
 +}
 +
++CpuCas01Lmm::~CpuCas01Lmm(){
++  unsigned int iter;
++  xbt_dynar_t power_tuple = NULL;
++  xbt_dynar_foreach(p_energy->power_range_watts_list, iter, power_tuple)
++    xbt_dynar_free(&power_tuple);
++  xbt_dynar_free(&p_energy->power_range_watts_list);
++  xbt_dynar_free(&p_powerPeakList);
++  xbt_free(p_energy);
++  return;
++}
++
 +bool CpuCas01Lmm::isUsed()
 +{
 +  return lmm_constraint_used(p_model->p_maxminSystem, p_constraint);
 +}
 +
 +void CpuCas01Lmm::updateState(tmgr_trace_event_t event_type, double value, double date)
 +{
 +  lmm_variable_t var = NULL;
 +  lmm_element_t elem = NULL;
 +
-     if (value > 0)
 +  if (event_type == p_powerEvent) {
 +    m_powerScale = value;
 +    lmm_update_constraint_bound(surf_cpu_model->p_maxminSystem, p_constraint,
 +                                m_core * m_powerScale *
 +                                m_powerPeak);
 +#ifdef HAVE_TRACING
 +    TRACE_surf_host_set_power(date, m_name,
 +                              m_core * m_powerScale *
 +                              m_powerPeak);
 +#endif
 +    while ((var = lmm_get_var_from_cnst
 +            (surf_cpu_model->p_maxminSystem, p_constraint, &elem))) {
 +      CpuCas01ActionLmmPtr action = static_cast<CpuCas01ActionLmmPtr>(static_cast<ActionLmmPtr>(lmm_variable_id(var)));
 +
 +      lmm_update_variable_bound(surf_cpu_model->p_maxminSystem,
 +                                action->p_variable,
 +                                m_powerScale * m_powerPeak);
 +    }
 +    if (tmgr_trace_event_free(event_type))
 +      p_powerEvent = NULL;
 +  } else if (event_type == p_stateEvent) {
-     else {
++    if (value > 0) {
++      if(p_stateCurrent == SURF_RESOURCE_OFF)
++        xbt_dynar_push_as(host_that_restart, char*, (char *)m_name);
 +      p_stateCurrent = SURF_RESOURCE_ON;
++    } else {
 +      lmm_constraint_t cnst = p_constraint;
 +
 +      p_stateCurrent = SURF_RESOURCE_OFF;
 +
 +      while ((var = lmm_get_var_from_cnst(surf_cpu_model->p_maxminSystem, cnst, &elem))) {
 +        ActionLmmPtr action = static_cast<ActionLmmPtr>(lmm_variable_id(var));
 +
 +        if (action->getState() == SURF_ACTION_RUNNING ||
 +            action->getState() == SURF_ACTION_READY ||
 +            action->getState() == SURF_ACTION_NOT_IN_THE_SYSTEM) {
 +          action->m_finish = date;
 +          action->setState(SURF_ACTION_FAILED);
 +        }
 +      }
 +    }
 +    if (tmgr_trace_event_free(event_type))
 +      p_stateEvent = NULL;
 +  } else {
 +    XBT_CRITICAL("Unknown event ! \n");
 +    xbt_abort();
 +  }
 +
 +  return;
 +}
 +
 +ActionPtr CpuCas01Lmm::execute(double size)
 +{
 +
 +  XBT_IN("(%s,%g)", m_name, size);
 +  CpuCas01ActionLmmPtr action = new CpuCas01ActionLmm(surf_cpu_model, size, p_stateCurrent != SURF_RESOURCE_ON);
 +
 +  action->m_suspended = 0;     /* Should be useless because of the
 +                                                   calloc but it seems to help valgrind... */
 +
 +  action->p_variable =
 +      lmm_variable_new(surf_cpu_model->p_maxminSystem, static_cast<ActionLmmPtr>(action),
 +                       action->m_priority,
 +                       m_powerScale * m_powerPeak, 1);
 +  if (surf_cpu_model->p_updateMechanism == UM_LAZY) {
 +    action->m_indexHeap = -1;
 +    action->m_lastUpdate = surf_get_clock();
 +    action->m_lastValue = 0.0;
 +  }
 +  lmm_expand(surf_cpu_model->p_maxminSystem, p_constraint,
 +             action->p_variable, 1.0);
 +  XBT_OUT();
 +  return action;
 +}
 +
 +ActionPtr CpuCas01Lmm::sleep(double duration)
 +{
 +  if (duration > 0)
 +    duration = MAX(duration, MAXMIN_PRECISION);
 +
 +  XBT_IN("(%s,%g)", m_name, duration);
 +  CpuCas01ActionLmmPtr action = dynamic_cast<CpuCas01ActionLmmPtr>(execute(1.0));
 +
 +  // FIXME: sleep variables should not consume 1.0 in lmm_expand
 +  action->m_maxDuration = duration;
 +  action->m_suspended = 2;
 +  if (duration == NO_MAX_DURATION) {
 +    /* Move to the *end* of the corresponding action set. This convention
 +       is used to speed up update_resource_state  */
 +    xbt_swag_remove(static_cast<ActionPtr>(action), action->p_stateSet);
 +    action->p_stateSet = cpu_running_action_set_that_does_not_need_being_checked;
 +    xbt_swag_insert(static_cast<ActionPtr>(action), action->p_stateSet);
 +  }
 +
 +  lmm_update_variable_weight(surf_cpu_model->p_maxminSystem,
 +                             action->p_variable, 0.0);
 +  if (surf_cpu_model->p_updateMechanism == UM_LAZY) {     // remove action from the heap
 +    action->heapRemove(surf_cpu_model->p_actionHeap);
 +    // 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(static_cast<ActionLmmPtr>(action), surf_cpu_model->p_modifiedSet);
 +  }
 +
 +  XBT_OUT();
 +  return action;
 +}
 +
++xbt_dynar_t CpuCas01Lmm::getWattsRangeList()
++{
++      xbt_dynar_t power_range_list;
++      xbt_dynar_t power_tuple;
++      int i = 0, pstate_nb=0;
++      xbt_dynar_t current_power_values;
++      double min_power, max_power;
++
++      if (m_properties == NULL)
++              return NULL;
++
++      char* all_power_values_str = (char*)xbt_dict_get_or_null(m_properties, "power_per_state");
++
++      if (all_power_values_str == NULL)
++              return NULL;
++
++
++      power_range_list = xbt_dynar_new(sizeof(xbt_dynar_t), NULL);
++      xbt_dynar_t all_power_values = xbt_str_split(all_power_values_str, ",");
++
++      pstate_nb = xbt_dynar_length(all_power_values);
++      for (i=0; i< pstate_nb; i++)
++      {
++              /* retrieve the power values associated with the current pstate */
++              current_power_values = xbt_str_split(xbt_dynar_get_as(all_power_values, i, char*), ":");
++              xbt_assert(xbt_dynar_length(current_power_values) > 1,
++                              "Power properties incorrectly defined - could not retrieve min and max power values for host %s",
++                              m_name);
++
++              /* min_power corresponds to the idle power (cpu load = 0) */
++              /* max_power is the power consumed at 100% cpu load       */
++              min_power = atof(xbt_dynar_get_as(current_power_values, 0, char*));
++              max_power = atof(xbt_dynar_get_as(current_power_values, 1, char*));
++
++              power_tuple = xbt_dynar_new(sizeof(double), NULL);
++              xbt_dynar_push_as(power_tuple, double, min_power);
++              xbt_dynar_push_as(power_tuple, double, max_power);
++
++              xbt_dynar_push_as(power_range_list, xbt_dynar_t, power_tuple);
++              xbt_dynar_free(&current_power_values);
++      }
++      xbt_dynar_free(&all_power_values);
++      return power_range_list;
++}
++
++/**
++ * Computes the power consumed by the host according to the current pstate and processor load
++ *
++ */
++double CpuCas01Lmm::getCurrentWattsValue(double cpu_load)
++{
++      xbt_dynar_t power_range_list = p_energy->power_range_watts_list;
++
++      if (power_range_list == NULL)
++      {
++              XBT_DEBUG("No power range properties specified for host %s", m_name);
++              return 0;
++      }
++      xbt_assert(xbt_dynar_length(power_range_list) == xbt_dynar_length(p_powerPeakList),
++                                              "The number of power ranges in the properties does not match the number of pstates for host %s",
++                                              m_name);
++
++    /* retrieve the power values associated with the current pstate */
++    xbt_dynar_t current_power_values = xbt_dynar_get_as(power_range_list, m_pstate, xbt_dynar_t);
++
++    /* min_power corresponds to the idle power (cpu load = 0) */
++    /* max_power is the power consumed at 100% cpu load       */
++    double min_power = xbt_dynar_get_as(current_power_values, 0, double);
++    double max_power = xbt_dynar_get_as(current_power_values, 1, double);
++    double power_slope = max_power - min_power;
++
++    double current_power = min_power + cpu_load * power_slope;
++
++      XBT_DEBUG("[get_current_watts] min_power=%f, max_power=%f, slope=%f", min_power, max_power, power_slope);
++    XBT_DEBUG("[get_current_watts] Current power (watts) = %f, load = %f", current_power, cpu_load);
++
++      return current_power;
++}
++
++/**
++ * Updates the total energy consumed as the sum of the current energy and
++ *                                             the energy consumed by the current action
++ */
++void CpuCas01Lmm::updateEnergy(double cpu_load)
++{
++  double start_time = p_energy->last_updated;
++  double finish_time = surf_get_clock();
++
++  XBT_DEBUG("[cpu_update_energy] action time interval=(%f-%f), current power peak=%f, current pstate=%d",
++                start_time, finish_time, m_powerPeak, m_pstate);
++  double current_energy = p_energy->total_energy;
++  double action_energy = getCurrentWattsValue(cpu_load)*(finish_time-start_time);
++
++  p_energy->total_energy = current_energy + action_energy;
++  p_energy->last_updated = finish_time;
++
++  XBT_DEBUG("[cpu_update_energy] old_energy_value=%f, action_energy_value=%f", current_energy, action_energy);
++}
++
++double CpuCas01Lmm::getCurrentPowerPeak()
++{
++  return m_powerPeak;
++}
++
++double CpuCas01Lmm::getPowerPeakAt(int pstate_index)
++{
++  xbt_dynar_t plist = p_powerPeakList;
++  xbt_assert((pstate_index <= xbt_dynar_length(plist)), "Invalid parameters (pstate index out of bounds)");
++
++  return xbt_dynar_get_as(plist, pstate_index, double);
++}
++
++int CpuCas01Lmm::getNbPstates()
++{
++  return xbt_dynar_length(p_powerPeakList);
++}
++
++void CpuCas01Lmm::setPowerPeakAt(int pstate_index)
++{
++  xbt_dynar_t plist = p_powerPeakList;
++  xbt_assert((pstate_index <= xbt_dynar_length(plist)), "Invalid parameters (pstate index out of bounds)");
++
++  double new_power_peak = xbt_dynar_get_as(plist, pstate_index, double);
++  m_pstate = pstate_index;
++  m_powerPeak = new_power_peak;
++}
++
++double CpuCas01Lmm::getConsumedEnergy()
++{
++  return p_energy->total_energy;
++}
 +
 +/**********
 + * Action *
 + **********/
 +
++/**
++ * Update the CPU total energy for a finished action
++ *
++ */
++void CpuCas01ActionLmm::updateEnergy()
++{
++  CpuCas01LmmPtr cpu  = static_cast<CpuCas01LmmPtr>(lmm_constraint_id(lmm_get_cnst_from_var
++                                                                                (p_model->p_maxminSystem,
++                                                                                                p_variable, 0)));
 +
++  if(cpu->p_energy->last_updated < surf_get_clock()) {
++      double load = lmm_constraint_get_usage(cpu->p_constraint) / cpu->m_powerPeak;
++    cpu->updateEnergy(load);
++  }
++}
diff --combined src/surf/cpu_cas01.hpp
index 779a350,0000000..5e12cc2
mode 100644,000000..100644
--- /dev/null
@@@ -1,62 -1,0 +1,88 @@@
-   CpuCas01LmmPtr createResource(const char *name, double power_peak, double power_scale,
 +#include "cpu.hpp"
 +
 +/***********
 + * Classes *
 + ***********/
 +class CpuCas01Model;
 +typedef CpuCas01Model *CpuCas01ModelPtr;
 +
 +class CpuCas01Lmm;
 +typedef CpuCas01Lmm *CpuCas01LmmPtr;
 +
 +class CpuCas01ActionLmm;
 +typedef CpuCas01ActionLmm *CpuCas01ActionLmmPtr;
 +
 +/*********
 + * Model *
 + *********/
 +class CpuCas01Model : public CpuModel {
 +public:
 +  CpuCas01Model();
 +  ~CpuCas01Model();
 +
 +  double (CpuCas01Model::*shareResources)(double now);
 +  void (CpuCas01Model::*updateActionsState)(double now, double delta);
 +
 +  void parseInit(sg_platf_host_cbarg_t host);  
-   CpuCas01Lmm(CpuCas01ModelPtr model, const char *name, double powerPeak,
-         double powerScale, tmgr_trace_t powerTrace, int core,
++  CpuCas01LmmPtr createResource(const char *name, xbt_dynar_t power_peak, int pstate,
++                                double power_scale,
 +                          tmgr_trace_t power_trace, int core,
 +                          e_surf_resource_state_t state_initial,
 +                          tmgr_trace_t state_trace,
 +                          xbt_dict_t cpu_properties);
 +  double shareResourcesFull(double now);  
 +  void addTraces();
 +};
 +
 +/************
 + * Resource *
 + ************/
++/*
++ * Energy-related properties for the cpu_cas01 model
++ */
++typedef struct energy_cpu_cas01 {
++      xbt_dynar_t power_range_watts_list;             /*< List of (min_power,max_power) pairs corresponding to each cpu pstate */
++      double total_energy;                                    /*< Total energy consumed by the host */
++      double last_updated;                                    /*< Timestamp of the last energy update event*/
++} s_energy_cpu_cas01_t, *energy_cpu_cas01_t;
++
 +class CpuCas01Lmm : public CpuLmm {
 +public:
++  CpuCas01Lmm(CpuCas01ModelPtr model, const char *name, xbt_dynar_t power_peak,
++        int pstate, double powerScale, tmgr_trace_t powerTrace, int core,
 +        e_surf_resource_state_t stateInitial, tmgr_trace_t stateTrace,
 +      xbt_dict_t properties) ;
++  ~CpuCas01Lmm();
 +  void updateState(tmgr_trace_event_t event_type, double value, double date);
 +  ActionPtr execute(double size);
 +  ActionPtr sleep(double duration);
 +
++  xbt_dynar_t getWattsRangeList();
++  double getCurrentWattsValue(double cpu_load);
++  void updateEnergy(double cpu_load);
++
++  double getCurrentPowerPeak();
++  double getPowerPeakAt(int pstate_index);
++  int getNbPstates();
++  void setPowerPeakAt(int pstate_index);
++  double getConsumedEnergy();
++
 +  bool isUsed();
 +
 +  tmgr_trace_event_t p_powerEvent;
++
++  xbt_dynar_t p_powerPeakList;                                /*< List of supported CPU capacities */
++  int m_pstate;                                                               /*< Current pstate (index in the power_peak_list)*/
++  energy_cpu_cas01_t p_energy;                                /*< Structure with energy-consumption data */
 +};
 +
 +/**********
 + * Action *
 + **********/
 +class CpuCas01ActionLmm: public CpuActionLmm {
 +public:
 +  CpuCas01ActionLmm() {};
 +  CpuCas01ActionLmm(ModelPtr model, double cost, bool failed): Action(model, cost, failed), CpuActionLmm(model, cost, failed) {};
++  void updateEnergy();
 +
 +};
diff --combined src/surf/cpu_ti.cpp
index e512106,0000000..545f2ba
mode 100644,000000..100644
--- /dev/null
@@@ -1,1000 -1,0 +1,1006 @@@
- XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_cpu_ti, surf,
 +#include "cpu_ti.hpp"
 +#include "trace_mgr_private.h"
 +#include "xbt/heap.h"
 +
 +#ifndef SURF_MODEL_CPUTI_H_
 +#define SURF_MODEL_CPUTI_H_
 +
 +extern "C" {
-       ("a %lf ind %d integral %lf ind + 1 %lf ind %lf time +1 %lf time %lf",
++XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_cpu_ti, surf_cpu,
 +                                "Logging specific to the SURF CPU TRACE INTEGRATION module");
 +}
 +
 +static xbt_swag_t cpu_ti_running_action_set_that_does_not_need_being_checked;
 +static xbt_swag_t cpu_ti_modified_cpu;
 +static xbt_heap_t cpu_ti_action_heap;
 +
 +static void cpu_ti_action_update_index_heap(void *action, int i);
 +
 +/*********
 + * Trace *
 + *********/
 +
 +CpuTiTrace::CpuTiTrace(tmgr_trace_t power_trace)
 +{
 +  s_tmgr_event_t val;
 +  unsigned int cpt;
 +  double integral = 0;
 +  double time = 0;
 +  int i = 0;
 +  p_timePoints = (double*) xbt_malloc0(sizeof(double) *
 +                  (xbt_dynar_length(power_trace->s_list.event_list) + 1));
 +  p_integral = (double*) xbt_malloc0(sizeof(double) *
 +                  (xbt_dynar_length(power_trace->s_list.event_list) + 1));
 +  m_nbPoints = xbt_dynar_length(power_trace->s_list.event_list);
 +  xbt_dynar_foreach(power_trace->s_list.event_list, cpt, val) {
 +    p_timePoints[i] = time;
 +    p_integral[i] = integral;
 +    integral += val.delta * val.value;
 +    time += val.delta;
 +    i++;
 +  }
 +  p_timePoints[i] = time;
 +  p_integral[i] = integral;
 +}
 +
 +CpuTiTrace::~CpuTiTrace()
 +{
 +  xbt_free(p_timePoints);
 +  xbt_free(p_integral);
 +}
 +
 +CpuTiTgmr::~CpuTiTgmr()
 +{
 +  if (p_trace)
 +    delete p_trace;
 +}
 +
 +/**
 +* \brief Integrate trace
 +*
 +* Wrapper around surf_cpu_integrate_trace_simple() to get
 +* the cyclic effect.
 +*
 +* \param trace Trace structure.
 +* \param a      Begin of interval
 +* \param b      End of interval
 +* \return the integrate value. -1 if an error occurs.
 +*/
 +double CpuTiTgmr::integrate(double a, double b)
 +{
 +  double first_chunk;
 +  double middle_chunk;
 +  double last_chunk;
 +  int a_index, b_index;
 +
 +  if ((a < 0.0) || (a > b)) {
 +    XBT_CRITICAL
 +        ("Error, invalid integration interval [%.2f,%.2f]. You probably have a task executing with negative computation amount. Check your code.",
 +         a, b);
 +    xbt_abort();
 +  }
 +  if (a == b)
 +    return 0.0;
 +
 +  if (m_type == TRACE_FIXED) {
 +    return ((b - a) * m_value);
 +  }
 +
 +  if (ceil(a / m_lastTime) == a / m_lastTime)
 +    a_index = 1 + (int) (ceil(a / m_lastTime));
 +  else
 +    a_index = (int) (ceil(a / m_lastTime));
 +
 +  b_index = (int) (floor(b / m_lastTime));
 +
 +  if (a_index > b_index) {      /* Same chunk */
 +    return p_trace->integrateSimple(a - (a_index -
 +                                              1) * m_lastTime,
 +                                         b -
 +                                         (b_index) *
 +                                         m_lastTime);
 +  }
 +
 +  first_chunk = p_trace->integrateSimple(a - (a_index -
 +                                                   1) *
 +                                              m_lastTime,
 +                                              m_lastTime);
 +  middle_chunk = (b_index - a_index) * m_total;
 +  last_chunk = p_trace->integrateSimple(0.0,
 +                                             b -
 +                                             (b_index) *
 +                                             m_lastTime);
 +
 +  XBT_DEBUG("first_chunk=%.2f  middle_chunk=%.2f  last_chunk=%.2f\n",
 +         first_chunk, middle_chunk, last_chunk);
 +
 +  return (first_chunk + middle_chunk + last_chunk);
 +}
 +
 +/**
 + * \brief Auxiliary function to calculate the integral between a and b.
 + *     It simply calculates the integral at point a and b and returns the difference 
 + *   between them.
 + * \param trace    Trace structure
 + * \param a        Initial point
 + * \param b  Final point
 + * \return  Integral
 +*/
 +double CpuTiTrace::integrateSimple(double a, double b)
 +{
 +  return integrateSimplePoint(b) - integrateSimplePoint(a);
 +}
 +
 +/**
 + * \brief Auxiliary function to calculate the integral at point a.
 + * \param trace    Trace structure
 + * \param a        point
 + * \return  Integral
 +*/
 +double CpuTiTrace::integrateSimplePoint(double a)
 +{
 +  double integral = 0;
 +  int ind;
 +  double a_aux = a;
 +  ind = binarySearch(p_timePoints, a, 0, m_nbPoints - 1);
 +  integral += p_integral[ind];
 +  XBT_DEBUG
-   XBT_DEBUG("Integral a %lf = %lf", a, integral);
++      ("a %f ind %d integral %f ind + 1 %f ind %f time +1 %f time %f",
 +       a, ind, integral, p_integral[ind + 1], p_integral[ind],
 +       p_timePoints[ind + 1], p_timePoints[ind]);
 +  double_update(&a_aux, p_timePoints[ind]);
 +  if (a_aux > 0)
 +    integral +=
 +        ((p_integral[ind + 1] -
 +          p_integral[ind]) / (p_timePoints[ind + 1] -
 +                              p_timePoints[ind])) * (a - p_timePoints[ind]);
-   XBT_DEBUG("amount %lf total %lf", amount, m_total);
++  XBT_DEBUG("Integral a %f = %f", a, integral);
 +
 +  return integral;
 +}
 +
 +/**
 +* \brief Calculate the time needed to execute "amount" on cpu.
 +*
 +* Here, amount can span multiple trace periods
 +*
 +* \param trace   CPU trace structure
 +* \param a        Initial time
 +* \param amount  Amount to be executed
 +* \return  End time
 +*/
 +double CpuTiTgmr::solve(double a, double amount)
 +{
 +  int quotient;
 +  double reduced_b;
 +  double reduced_amount;
 +  double reduced_a;
 +  double b;
 +
 +/* Fix very small negative numbers */
 +  if ((a < 0.0) && (a > -EPSILON)) {
 +    a = 0.0;
 +  }
 +  if ((amount < 0.0) && (amount > -EPSILON)) {
 +    amount = 0.0;
 +  }
 +
 +/* Sanity checks */
 +  if ((a < 0.0) || (amount < 0.0)) {
 +    XBT_CRITICAL
 +        ("Error, invalid parameters [a = %.2f, amount = %.2f]. You probably have a task executing with negative computation amount. Check your code.",
 +         a, amount);
 +    xbt_abort();
 +  }
 +
 +/* At this point, a and amount are positive */
 +
 +  if (amount < EPSILON)
 +    return a;
 +
 +/* Is the trace fixed ? */
 +  if (m_type == TRACE_FIXED) {
 +    return (a + (amount / m_value));
 +  }
 +
-   XBT_DEBUG("Quotient: %d reduced_amount: %lf reduced_a: %lf", quotient,
++  XBT_DEBUG("amount %f total %f", amount, m_total);
 +/* Reduce the problem to one where amount <= trace_total */
 +  quotient = (int) (floor(amount / m_total));
 +  reduced_amount = (m_total) * ((amount / m_total) -
 +                                     floor(amount / m_total));
 +  reduced_a = a - (m_lastTime) * (int) (floor(a / m_lastTime));
 +
-     XBT_DEBUG("No availabily trace. Constant value = %lf", value);
++  XBT_DEBUG("Quotient: %d reduced_amount: %f reduced_a: %f", quotient,
 +         reduced_amount, reduced_a);
 +
 +/* Now solve for new_amount which is <= trace_total */
 +/*
 +   fprintf(stderr,"reduced_a = %.2f\n",reduced_a);
 +   fprintf(stderr,"reduced_amount = %.2f\n",reduced_amount);
 + */
 +  reduced_b = solveSomewhatSimple(reduced_a, reduced_amount);
 +
 +/* Re-map to the original b and amount */
 +  b = (m_lastTime) * (int) (floor(a / m_lastTime)) +
 +      (quotient * m_lastTime) + reduced_b;
 +  return b;
 +}
 +
 +/**
 +* \brief Auxiliary function to solve integral
 +*
 +* Here, amount is <= trace->total
 +* and a <=trace->last_time
 +*
 +*/
 +double CpuTiTgmr::solveSomewhatSimple(double a, double amount)
 +{
 +  double amount_till_end;
 +  double b;
 +
 +  XBT_DEBUG("Solve integral: [%.2f, amount=%.2f]", a, amount);
 +  amount_till_end = integrate(a, m_lastTime);
 +/*
 +   fprintf(stderr,"amount_till_end=%.2f\n",amount_till_end);
 + */
 +
 +  if (amount_till_end > amount) {
 +    b = p_trace->solveSimple(a, amount);
 +  } else {
 +    b = m_lastTime + p_trace->solveSimple(0.0, amount - amount_till_end);
 +  }
 +  return b;
 +}
 +
 +/**
 + * \brief Auxiliary function to solve integral.
 + *  It returns the date when the requested amount of flops is available
 + * \param trace    Trace structure
 + * \param a        Initial point
 + * \param amount  Amount of flops 
 + * \return The date when amount is available.
 +*/
 +double CpuTiTrace::solveSimple(double a, double amount)
 +{
 +  double integral_a;
 +  int ind;
 +  double time;
 +  integral_a = integrateSimplePoint(a);
 +  ind = binarySearch(p_integral, integral_a + amount, 0, m_nbPoints - 1);
 +  time = p_timePoints[ind];
 +  time +=
 +      (integral_a + amount -
 +       p_integral[ind]) / ((p_integral[ind + 1] -
 +                                 p_integral[ind]) /
 +                                (p_timePoints[ind + 1] -
 +                                 p_timePoints[ind]));
 +
 +  return time;
 +}
 +
 +/**
 +* \brief Auxiliary function to update the CPU power scale.
 +*
 +*  This function uses the trace structure to return the power scale at the determined time a.
 +* \param trace    Trace structure to search the updated power scale
 +* \param a        Time
 +* \return CPU power scale
 +*/
 +double CpuTiTgmr::getPowerScale(double a)
 +{
 +  double reduced_a;
 +  int point;
 +  s_tmgr_event_t val;
 +
 +  reduced_a = a - floor(a / m_lastTime) * m_lastTime;
 +  point = p_trace->binarySearch(p_trace->p_timePoints, reduced_a, 0,
 +                                p_trace->m_nbPoints - 1);
 +  xbt_dynar_get_cpy(p_powerTrace->s_list.event_list, point, &val);
 +  return val.value;
 +}
 +
 +/**
 +* \brief Creates a new integration trace from a tmgr_trace_t
 +*
 +* \param  power_trace    CPU availability trace
 +* \param  value          Percentage of CPU power available (useful to fixed tracing)
 +* \param  spacing        Initial spacing
 +* \return  Integration trace structure
 +*/
 +CpuTiTgmr::CpuTiTgmr(tmgr_trace_t power_trace, double value)
 +{
 +  double total_time = 0.0;
 +  s_tmgr_event_t val;
 +  unsigned int cpt;
 +  p_trace = 0;
 +
 +/* no availability file, fixed trace */
 +  if (!power_trace) {
 +    m_type = TRACE_FIXED;
 +    m_value = value;
-     XBT_DEBUG("a %lf low %d high %d mid %d value %lf", a, low, high, mid,
++    XBT_DEBUG("No availability trace. Constant value = %lf", value);
 +    return;
 +  }
 +
 +  /* only one point available, fixed trace */
 +  if (xbt_dynar_length(power_trace->s_list.event_list) == 1) {
 +    xbt_dynar_get_cpy(power_trace->s_list.event_list, 0, &val);
 +    m_type = TRACE_FIXED;
 +    m_value = val.value;
 +    return;
 +  }
 +
 +  m_type = TRACE_DYNAMIC;
 +  p_powerTrace = power_trace;
 +
 +  /* count the total time of trace file */
 +  xbt_dynar_foreach(power_trace->s_list.event_list, cpt, val) {
 +    total_time += val.delta;
 +  }
 +  p_trace = new CpuTiTrace(power_trace);
 +  m_lastTime = total_time;
 +  m_total = p_trace->integrateSimple(0, total_time);
 +
 +  XBT_DEBUG("Total integral %lf, last_time %lf ",
 +            m_total, m_lastTime);
 +}
 +
 +/**
 + * \brief Binary search in array.
 + *  It returns the first point of the interval in which "a" is. 
 + * \param array    Array
 + * \param a        Value to search
 + * \param low     Low bound to search in array
 + * \param high    Upper bound to search in array
 + * \return Index of point
 +*/
 +int CpuTiTrace::binarySearch(double *array, double a, int low, int high)
 +{
 +  xbt_assert(low < high, "Wrong parameters: low (%d) should be smaller than"
 +      " high (%d)", low, high);
 +
 +  int mid;
 +  do {
 +    mid = low + (high - low) / 2;
-                          double powerPeak,
++    XBT_DEBUG("a %f low %d high %d mid %d value %f", a, low, high, mid,
 +        array[mid]);
 +
 +    if (array[mid] > a)
 +      high = mid;
 +    else
 +      low = mid;
 +  }
 +  while (low < high - 1);
 +
 +  return low;
 +}
 +
 +/*************
 + * CallBacks *
 + *************/
 +
 +static void parse_cpu_ti_init(sg_platf_host_cbarg_t host){
 +  ((CpuTiModelPtr)surf_cpu_model)->parseInit(host);
 +}
 +
 +static void add_traces_cpu_ti(){
 +  surf_cpu_model->addTraces();
 +}
 +
 +static void cpu_ti_define_callbacks()
 +{
 +  sg_platf_host_add_cb(parse_cpu_ti_init);
 +  sg_platf_postparse_add_cb(add_traces_cpu_ti);
 +}
 +
 +/*********
 + * Model *
 + *********/
 +
 +void surf_cpu_model_init_ti()
 +{
 +  xbt_assert(!surf_cpu_model,"CPU model already initialized. This should not happen.");
 +  surf_cpu_model = new CpuTiModel();
 +  cpu_ti_define_callbacks();
 +  ModelPtr model = static_cast<ModelPtr>(surf_cpu_model);
 +  xbt_dynar_push(model_list, &model);
 +}
 +
 +CpuTiModel::CpuTiModel() : CpuModel("cpu_ti")
 +{
 +  xbt_assert(!surf_cpu_model,"CPU model already initialized. This should not happen.");
 +  ActionPtr action;
 +  CpuTi cpu;
 +
 +  cpu_ti_running_action_set_that_does_not_need_being_checked =
 +      xbt_swag_new(xbt_swag_offset(*action, p_stateHookup));
 +
 +  cpu_ti_modified_cpu =
 +      xbt_swag_new(xbt_swag_offset(cpu, p_modifiedCpuHookup));
 +
 +  cpu_ti_action_heap = xbt_heap_new(8, NULL);
 +  xbt_heap_set_update_callback(cpu_ti_action_heap,
 +                               cpu_ti_action_update_index_heap);
 +}
 +
 +CpuTiModel::~CpuTiModel()
 +{
 +  void **cpu;
 +  xbt_lib_cursor_t cursor;
 +  char *key;
 +
 +  xbt_lib_foreach(host_lib, cursor, key, cpu){
 +    if(cpu[SURF_CPU_LEVEL])
 +    {
 +        CpuTiPtr CPU = dynamic_cast<CpuTiPtr>(static_cast<ResourcePtr>(cpu[SURF_CPU_LEVEL]));
 +        xbt_swag_free(CPU->p_actionSet);
 +        delete CPU->p_availTrace;
 +    }
 +  }
 +
 +  surf_cpu_model = NULL;
 +
 +  xbt_swag_free
 +      (cpu_ti_running_action_set_that_does_not_need_being_checked);
 +  xbt_swag_free(cpu_ti_modified_cpu);
 +  cpu_ti_running_action_set_that_does_not_need_being_checked = NULL;
 +  xbt_heap_free(cpu_ti_action_heap);
 +}
 +
 +void CpuTiModel::parseInit(sg_platf_host_cbarg_t host)
 +{
 +  createResource(host->id,
 +        host->power_peak,
++        host->pstate,
 +        host->power_scale,
 +        host->power_trace,
 +        host->core_amount,
 +        host->initial_state,
 +        host->state_trace,
 +        host->properties);
 +}
 +
 +CpuTiPtr CpuTiModel::createResource(const char *name,
-   CpuTiPtr cpu = new CpuTi(this, name, powerPeak, powerScale, powerTrace,
++                             xbt_dynar_t powerPeak,
++                             int pstate,
 +                           double powerScale,
 +                           tmgr_trace_t powerTrace,
 +                           int core,
 +                           e_surf_resource_state_t stateInitial,
 +                           tmgr_trace_t stateTrace,
 +                           xbt_dict_t cpuProperties)
 +{
 +  tmgr_trace_t empty_trace;
 +  s_tmgr_event_t val;
 +  CpuTiActionPtr cpuAction;
 +  xbt_assert(core==1,"Multi-core not handled with this model yet");
 +  xbt_assert(!surf_cpu_resource_priv(surf_cpu_resource_by_name(name)),
 +              "Host '%s' declared several times in the platform file",
 +              name);
-   XBT_DEBUG("Share resources, min next event date: %lf", min_action_duration);
++  CpuTiPtr cpu = new CpuTi(this, name, powerPeak, pstate, powerScale, powerTrace,
 +                         core, stateInitial, stateTrace, cpuProperties);
 +  xbt_lib_set(host_lib, name, SURF_CPU_LEVEL, static_cast<ResourcePtr>(cpu));
 +  return (CpuTiPtr) xbt_lib_get_elm_or_null(host_lib, name);
 +}
 +
 +CpuTiActionPtr CpuTiModel::createAction(double cost, bool failed)
 +{
 +  return NULL;//new CpuTiAction(this, cost, failed);
 +}
 +
 +double CpuTiModel::shareResources(double now)
 +{
 +  void *_cpu, *_cpu_next;
 +  double min_action_duration = -1;
 +
 +/* iterates over modified cpus to update share resources */
 +  xbt_swag_foreach_safe(_cpu, _cpu_next, cpu_ti_modified_cpu) {
 +    static_cast<CpuTiPtr>(_cpu)->updateActionFinishDate(now);
 +  }
 +/* get the min next event if heap not empty */
 +  if (xbt_heap_size(cpu_ti_action_heap) > 0)
 +    min_action_duration = xbt_heap_maxkey(cpu_ti_action_heap) - now;
 +
-     /* update remaining amout of all actions */
++  XBT_DEBUG("Share resources, min next event date: %f", min_action_duration);
 +
 +  return min_action_duration;
 +}
 +
 +void CpuTiModel::updateActionsState(double now, double delta)
 +{
 +  while ((xbt_heap_size(cpu_ti_action_heap) > 0)
 +         && (xbt_heap_maxkey(cpu_ti_action_heap) <= now)) {
 +    CpuTiActionPtr action = (CpuTiActionPtr) xbt_heap_pop(cpu_ti_action_heap);
 +    XBT_DEBUG("Action %p: finish", action);
 +    action->m_finish = surf_get_clock();
 +    /* set the remains to 0 due to precision problems when updating the remaining amount */
 +    action->m_remains = 0;
 +    action->setState(SURF_ACTION_DONE);
- CpuTi::CpuTi(CpuTiModelPtr model, const char *name, double powerPeak,
-         double powerScale, tmgr_trace_t powerTrace, int core,
++    /* update remaining amount of all actions */
 +    action->p_cpu->updateRemainingAmount(surf_get_clock());
 +  }
 +}
 +
 +void CpuTiModel::addTraces()
 +{
 +  xbt_dict_cursor_t cursor = NULL;
 +  char *trace_name, *elm;
 +
 +  static int called = 0;
 +
 +  if (called)
 +    return;
 +  called = 1;
 +
 +/* connect all traces relative to hosts */
 +  xbt_dict_foreach(trace_connect_list_host_avail, cursor, trace_name, elm) {
 +    tmgr_trace_t trace = (tmgr_trace_t) xbt_dict_get_or_null(traces_set_list, trace_name);
 +    CpuTiPtr cpu = static_cast<CpuTiPtr>(surf_cpu_resource_priv(surf_cpu_resource_by_name(elm)));
 +
 +    xbt_assert(cpu, "Host %s undefined", elm);
 +    xbt_assert(trace, "Trace %s undefined", trace_name);
 +
 +    if (cpu->p_stateEvent) {
 +      XBT_DEBUG("Trace already configured for this CPU(%s), ignoring it",
 +             elm);
 +      continue;
 +    }
 +    XBT_DEBUG("Add state trace: %s to CPU(%s)", trace_name, elm);
 +    cpu->p_stateEvent = tmgr_history_add_trace(history, trace, 0.0, 0, static_cast<ResourcePtr>(cpu));
 +  }
 +
 +  xbt_dict_foreach(trace_connect_list_power, cursor, trace_name, elm) {
 +    tmgr_trace_t trace = (tmgr_trace_t) xbt_dict_get_or_null(traces_set_list, trace_name);
 +    CpuTiPtr cpu = dynamic_cast<CpuTiPtr>(static_cast<ResourcePtr>(surf_cpu_resource_priv(surf_cpu_resource_by_name(elm))));
 +
 +    xbt_assert(cpu, "Host %s undefined", elm);
 +    xbt_assert(trace, "Trace %s undefined", trace_name);
 +
 +    XBT_DEBUG("Add power trace: %s to CPU(%s)", trace_name, elm);
 +    if (cpu->p_availTrace)
 +      delete cpu->p_availTrace;
 +
 +    cpu->p_availTrace = new CpuTiTgmr(trace, cpu->m_powerScale);
 +
 +    /* add a fake trace event if periodicity == 0 */
 +    if (trace && xbt_dynar_length(trace->s_list.event_list) > 1) {
 +      s_tmgr_event_t val;
 +      xbt_dynar_get_cpy(trace->s_list.event_list,
 +                        xbt_dynar_length(trace->s_list.event_list) - 1, &val);
 +      if (val.delta == 0) {
 +        tmgr_trace_t empty_trace;
 +        empty_trace = tmgr_empty_trace_new();
 +        cpu->p_powerEvent =
 +            tmgr_history_add_trace(history, empty_trace,
 +                                   cpu->p_availTrace->m_lastTime, 0, static_cast<ResourcePtr>(cpu));
 +      }
 +    }
 +  }
 +}
 +
 +/************
 + * Resource *
 + ************/
-   m_powerPeak = powerPeak;
++CpuTi::CpuTi(CpuTiModelPtr model, const char *name, xbt_dynar_t powerPeak,
++        int pstate, double powerScale, tmgr_trace_t powerTrace, int core,
 +        e_surf_resource_state_t stateInitial, tmgr_trace_t stateTrace,
 +      xbt_dict_t properties) :
 +      Resource(model, name, properties), Cpu(model, name, properties) {
 +  p_stateCurrent = stateInitial;
-        p_powerEvent =
 +  m_powerScale = powerScale;
 +  m_core = core;
 +  tmgr_trace_t empty_trace;           
 +  s_tmgr_event_t val;         
 +  xbt_assert(core==1,"Multi-core not handled with this model yet");
 +  XBT_DEBUG("power scale %lf", powerScale);
 +  p_availTrace = new CpuTiTgmr(powerTrace, powerScale);
 +
 +  CpuTiActionPtr action;
 +  p_actionSet = xbt_swag_new(xbt_swag_offset(*action, p_cpuListHookup));
 +
++  xbt_dynar_get_cpy(powerPeak, 0, &m_powerPeak);
++  xbt_dynar_free(&powerPeak);  /* kill memory leak */
++  m_pstate = pstate;
++  XBT_DEBUG("CPU create: peak=%f, pstate=%d", m_powerPeak, m_pstate);
++
 +  p_modifiedCpuHookup.prev = 0;
 +  p_modifiedCpuHookup.next = 0;
 +
 +  if (stateTrace)
 +    p_stateEvent = tmgr_history_add_trace(history, stateTrace, 0.0, 0, static_cast<ResourcePtr>(this));
 +  if (powerTrace && xbt_dynar_length(powerTrace->s_list.event_list) > 1) {
 +    // add a fake trace event if periodicity == 0 
 +    xbt_dynar_get_cpy(powerTrace->s_list.event_list,
 +                      xbt_dynar_length(powerTrace->s_list.event_list) - 1, &val);
 +    if (val.delta == 0) {
 +      empty_trace = tmgr_empty_trace_new();
-   surf_watched_hosts();
++      p_powerEvent =
 +        tmgr_history_add_trace(history, empty_trace,
 +                               p_availTrace->m_lastTime, 0, static_cast<ResourcePtr>(this));
 +    }
 +  }
 +};
 +
 +void CpuTi::updateState(tmgr_trace_event_t event_type,
 +                        double value, double date)
 +{
 +  void *_action;
 +  CpuTiActionPtr action;
 +
-     XBT_DEBUG("Finish trace date: %lf value %lf date %lf", surf_get_clock(),
 +  if (event_type == p_powerEvent) {
 +    tmgr_trace_t power_trace;
 +    CpuTiTgmrPtr trace;
 +    s_tmgr_event_t val;
 +
-     XBT_DEBUG("value %lf", val.value);
++    XBT_DEBUG("Finish trace date: %f value %lf date %f", surf_get_clock(),
 +           value, date);
 +    /* update remaining of actions and put in modified cpu swag */
 +    updateRemainingAmount(date);
 +    xbt_swag_insert(this, cpu_ti_modified_cpu);
 +
 +    power_trace = p_availTrace->p_powerTrace;
 +    xbt_dynar_get_cpy(power_trace->s_list.event_list,
 +                      xbt_dynar_length(power_trace->s_list.event_list) - 1, &val);
 +    /* free old trace */
 +    delete p_availTrace;
 +    m_powerScale = val.value;
 +
 +    trace = new CpuTiTgmr(TRACE_FIXED, val.value);
-     if (value > 0)
++    XBT_DEBUG("value %f", val.value);
 +
 +    p_availTrace = trace;
 +
 +    if (tmgr_trace_event_free(event_type))
 +      p_powerEvent = NULL;
 +
 +  } else if (event_type == p_stateEvent) {
-     else {
++    if (value > 0) {
++      if(p_stateCurrent == SURF_RESOURCE_OFF)
++        xbt_dynar_push_as(host_that_restart, char*, (char *)m_name);
 +      p_stateCurrent = SURF_RESOURCE_ON;
-         ("Update finish time: Cpu(%s) Action: %p, Start Time: %lf Finish Time: %lf Max duration %lf",
++    } else {
 +      p_stateCurrent = SURF_RESOURCE_OFF;
 +
 +      /* put all action running on cpu to failed */
 +      xbt_swag_foreach(_action, p_actionSet) {
 +      action = static_cast<CpuTiActionPtr>(_action);
 +        if (action->getState() == SURF_ACTION_RUNNING
 +         || action->getState() == SURF_ACTION_READY
 +         || action->getState() == SURF_ACTION_NOT_IN_THE_SYSTEM) {
 +          action->m_finish = date;
 +          action->setState(SURF_ACTION_FAILED);
 +          if (action->m_indexHeap >= 0) {
 +            CpuTiActionPtr heap_act = (CpuTiActionPtr)
 +                xbt_heap_remove(cpu_ti_action_heap, action->m_indexHeap);
 +            if (heap_act != action)
 +              DIE_IMPOSSIBLE;
 +          }
 +        }
 +      }
 +    }
 +    if (tmgr_trace_event_free(event_type))
 +      p_stateEvent = NULL;
 +  } else {
 +    XBT_CRITICAL("Unknown event ! \n");
 +    xbt_abort();
 +  }
 +
 +  return;
 +}
 +
 +void CpuTi::updateActionFinishDate(double now)
 +{
 +  void *_action;
 +  CpuTiActionPtr action;
 +  double sum_priority = 0.0, total_area, min_finish = -1;
 +
 +/* update remaning amount of actions */
 +updateRemainingAmount(now);
 +
 +  xbt_swag_foreach(_action, p_actionSet) {
 +    action = static_cast<CpuTiActionPtr>(_action);
 +    /* action not running, skip it */
 +    if (action->p_stateSet !=
 +        surf_cpu_model->p_runningActionSet)
 +      continue;
 +
 +    /* bogus priority, skip it */
 +    if (action->m_priority <= 0)
 +      continue;
 +
 +    /* action suspended, skip it */
 +    if (action->m_suspended != 0)
 +      continue;
 +
 +    sum_priority += 1.0 / action->m_priority;
 +  }
 +  m_sumPriority = sum_priority;
 +
 +  xbt_swag_foreach(_action, p_actionSet) {
 +    action = static_cast<CpuTiActionPtr>(_action);
 +    min_finish = -1;
 +    /* action not running, skip it */
 +    if (action->p_stateSet !=
 +        surf_cpu_model->p_runningActionSet)
 +      continue;
 +
 +    /* verify if the action is really running on cpu */
 +    if (action->m_suspended == 0 && action->m_priority > 0) {
 +      /* total area needed to finish the action. Used in trace integration */
 +      total_area =
 +          (action->m_remains) * sum_priority *
 +           action->m_priority;
 +
 +      total_area /= m_powerPeak;
 +
 +      action->m_finish = p_availTrace->solve(now, total_area);
 +      /* verify which event will happen before (max_duration or finish time) */
 +      if (action->m_maxDuration != NO_MAX_DURATION &&
 +          action->m_start + action->m_maxDuration < action->m_finish)
 +        min_finish = action->m_start + action->m_maxDuration;
 +      else
 +        min_finish = action->m_finish;
 +    } else {
 +      /* put the max duration time on heap */
 +      if (action->m_maxDuration != NO_MAX_DURATION)
 +        min_finish = action->m_start + action->m_maxDuration;
 +    }
 +    /* add in action heap */
 +    XBT_DEBUG("action(%p) index %d", action, action->m_indexHeap);
 +    if (action->m_indexHeap >= 0) {
 +      CpuTiActionPtr heap_act = (CpuTiActionPtr)
 +          xbt_heap_remove(cpu_ti_action_heap, action->m_indexHeap);
 +      if (heap_act != action)
 +        DIE_IMPOSSIBLE;
 +    }
 +    if (min_finish != NO_MAX_DURATION)
 +      xbt_heap_push(cpu_ti_action_heap, action, min_finish);
 +
 +    XBT_DEBUG
-   XBT_DEBUG("Flops total: %lf, Last update %lf", area_total,
++        ("Update finish time: Cpu(%s) Action: %p, Start Time: %f Finish Time: %f Max duration %f",
 +         m_name, action, action->m_start,
 +         action->m_finish,
 +         action->m_maxDuration);
 +  }
 +/* remove from modified cpu */
 +  xbt_swag_remove(this, cpu_ti_modified_cpu);
 +}
 +
 +bool CpuTi::isUsed()
 +{
 +  return xbt_swag_size(p_actionSet);
 +}
 +
 +
 +
 +double CpuTi::getAvailableSpeed()
 +{
 +  m_powerScale = p_availTrace->getPowerScale(surf_get_clock());
 +  return Cpu::getAvailableSpeed();
 +}
 +
 +/**
 +* \brief Update the remaining amount of actions
 +*
 +* \param  now    Current time
 +*/
 +void CpuTi::updateRemainingAmount(double now)
 +{
 +  double area_total;
 +  void* _action;
 +  CpuTiActionPtr action;
 +
 +  /* already updated */
 +  if (m_lastUpdate >= now)
 +    return;
 +
 +/* calcule the surface */
 +  area_total = p_availTrace->integrate(m_lastUpdate, now) * m_powerPeak;
-     XBT_DEBUG("Update remaining action(%p) remaining %lf", action,
++  XBT_DEBUG("Flops total: %f, Last update %f", area_total,
 +         m_lastUpdate);
 +
 +  xbt_swag_foreach(_action, p_actionSet) {
 +    action = static_cast<CpuTiActionPtr>(_action);
 +    /* action not running, skip it */
 +    if (action->p_stateSet !=
 +        getModel()->p_runningActionSet)
 +      continue;
 +
 +    /* bogus priority, skip it */
 +    if (action->m_priority <= 0)
 +      continue;
 +
 +    /* action suspended, skip it */
 +    if (action->m_suspended != 0)
 +      continue;
 +
 +    /* action don't need update */
 +    if (action->m_start >= now)
 +      continue;
 +
 +    /* skip action that are finishing now */
 +    if (action->m_finish >= 0
 +        && action->m_finish <= now)
 +      continue;
 +
 +    /* update remaining */
 +    double_update(&(action->m_remains),
 +                  area_total / (m_sumPriority *
 +                                action->m_priority));
++    XBT_DEBUG("Update remaining action(%p) remaining %f", action,
 +           action->m_remains);
 +  }
 +  m_lastUpdate = now;
 +}
 +
 +CpuActionPtr CpuTi::execute(double size)
 +{
 +  return _execute(size);
 +}
 +
 +CpuTiActionPtr CpuTi::_execute(double size)
 +{
 +  XBT_IN("(%s,%g)", m_name, size);
 +  CpuTiActionPtr action = new CpuTiAction(static_cast<CpuTiModelPtr>(p_model), size, p_stateCurrent != SURF_RESOURCE_ON);
 +
 +  action->p_cpu = this;
 +  action->m_indexHeap = -1;
 +
 +  xbt_swag_insert(this, cpu_ti_modified_cpu);
 +
 +  xbt_swag_insert(action, p_actionSet);
 +
 +  action->m_suspended = 0;        /* Should be useless because of the
 +              »                     calloc but it seems to help valgrind... */
 +
 +  XBT_OUT();
 +  return action;
 +}
 +
 +
 +CpuActionPtr CpuTi::sleep(double duration)
 +{
 +  if (duration > 0)
 +    duration = MAX(duration, MAXMIN_PRECISION);
 +
 +  XBT_IN("(%s,%g)", m_name, duration);
 +  CpuTiActionPtr action = _execute(1.0);
 +  action->m_maxDuration = duration;
 +  action->m_suspended = 2;
 +  if (duration == NO_MAX_DURATION) {
 +    /* Move to the *end* of the corresponding action set. This convention
 +       is used to speed up update_resource_state  */
 +    xbt_swag_remove(static_cast<ActionPtr>(action), action->p_stateSet);
 +    action->p_stateSet = cpu_ti_running_action_set_that_does_not_need_being_checked;
 +    xbt_swag_insert(static_cast<ActionPtr>(action), action->p_stateSet);
 +  }
 +  XBT_OUT();
 +  return action;
 +}
 +
 +void CpuTi::printCpuTiModel()
 +{
 +  std::cout << getModel()->getName() << "<<plop"<< std::endl;
 +};
 +
 +/**********
 + * Action *
 + **********/
 +static void cpu_ti_action_update_index_heap(void *action, int i)
 +{
 +  ((CpuTiActionPtr)action)->updateIndexHeap(i); 
 +}
 +void CpuTiAction::updateIndexHeap(int i)
 +{
 +  m_indexHeap = i;
 +}
 +
 +void CpuTiAction::setState(e_surf_action_state_t state)
 +{
 +  Action::setState(state);
 +  xbt_swag_insert(p_cpu, cpu_ti_modified_cpu);
 +}
 +
 +int CpuTiAction::unref()
 +{
 +  m_refcount--;
 +  if (!m_refcount) {
 +    xbt_swag_remove(static_cast<ActionPtr>(this), p_stateSet);
 +    /* remove from action_set */
 +    xbt_swag_remove(this, p_cpu->p_actionSet);
 +    /* remove from heap */
 +    xbt_heap_remove(cpu_ti_action_heap, this->m_indexHeap);
 +    xbt_swag_insert(p_cpu, cpu_ti_modified_cpu);
 +    delete this;
 +    return 1;
 +  }
 +  return 0;
 +}
 +
 +void CpuTiAction::cancel()
 +{
 +  this->setState(SURF_ACTION_FAILED);
 +  xbt_heap_remove(cpu_ti_action_heap, this->m_indexHeap);
 +  xbt_swag_insert(p_cpu, cpu_ti_modified_cpu);
 +  return;
 +}
 +
 +void CpuTiAction::recycle()
 +{
 +  DIE_IMPOSSIBLE;
 +}
 +
 +void CpuTiAction::suspend()
 +{
 +  XBT_IN("(%p)", this);
 +  if (m_suspended != 2) {
 +    m_suspended = 1;
 +    xbt_heap_remove(cpu_ti_action_heap, m_indexHeap);
 +    xbt_swag_insert(p_cpu, cpu_ti_modified_cpu);
 +  }
 +  XBT_OUT();
 +}
 +
 +void CpuTiAction::resume()
 +{
 +  XBT_IN("(%p)", this);
 +  if (m_suspended != 2) {
 +    m_suspended = 0;
 +    xbt_swag_insert(p_cpu, cpu_ti_modified_cpu);
 +  }
 +  XBT_OUT();
 +}
 +
 +bool CpuTiAction::isSuspended()
 +{
 +  return m_suspended == 1;
 +}
 +
 +void CpuTiAction::setMaxDuration(double duration)
 +{
 +  double min_finish;
 +
 +  XBT_IN("(%p,%g)", this, duration);
 +
 +  m_maxDuration = duration;
 +
 +  if (duration >= 0)
 +    min_finish = (m_start + m_maxDuration) < m_finish ?
 +                 (m_start + m_maxDuration) : m_finish;
 +  else
 +    min_finish = m_finish;
 +
 +/* add in action heap */
 +  if (m_indexHeap >= 0) {
 +    CpuTiActionPtr heap_act = (CpuTiActionPtr)
 +        xbt_heap_remove(cpu_ti_action_heap, m_indexHeap);
 +    if (heap_act != this)
 +      DIE_IMPOSSIBLE;
 +  }
 +  xbt_heap_push(cpu_ti_action_heap, this, min_finish);
 +
 +  XBT_OUT();
 +}
 +
 +void CpuTiAction::setPriority(double priority)
 +{
 +  XBT_IN("(%p,%g)", this, priority);
 +  m_priority = priority;
 +  xbt_swag_insert(p_cpu, cpu_ti_modified_cpu);
 +  XBT_OUT();
 +}
 +
 +double CpuTiAction::getRemains()
 +{
 +  XBT_IN("(%p)", this);
 +  p_cpu->updateRemainingAmount(surf_get_clock());
 +  XBT_OUT();
 +  return m_remains;
 +}
 +
 +static void check() {
 +  CpuTiActionPtr cupAction = new CpuTiAction(NULL, 0, true);
 +}
 +
 +#endif /* SURF_MODEL_CPUTI_H_ */
 +
diff --combined src/surf/cpu_ti.hpp
index 6d52dd9,0000000..cccac33
mode 100644,000000..100644
--- /dev/null
@@@ -1,163 -1,0 +1,178 @@@
-   CpuTiPtr createResource(const char *name, double power_peak, double power_scale,
 +#include "cpu.hpp"
 +#include "trace_mgr_private.h"
 +#include "surf/surf_routing.h"
 +
 +/* Epsilon */
 +#define EPSILON 0.000000001
 +
 +/***********
 + * Classes *
 + ***********/
 +class CpuTiTrace;
 +typedef CpuTiTrace *CpuTiTracePtr;
 +
 +class CpuTiTgmr;
 +typedef CpuTiTgmr *CpuTiTgmrPtr;
 +
 +class CpuTiModel;
 +typedef CpuTiModel *CpuTiModelPtr;
 +
 +class CpuTi;
 +typedef CpuTi *CpuTiPtr;
 +
 +class CpuTiAction;
 +typedef CpuTiAction *CpuTiActionPtr;
 +
 +/*********
 + * Trace *
 + *********/
 +class CpuTiTrace {
 +public:
 +  CpuTiTrace(tmgr_trace_t powerTrace);
 +  ~CpuTiTrace();
 +
 +  double integrateSimple(double a, double b);
 +  double integrateSimplePoint(double a);
 +  double solveSimple(double a, double amount);
 +
 +  double *p_timePoints;
 +  double *p_integral;
 +  int m_nbPoints;
 +  int binarySearch(double *array, double a, int low, int high);
 +
 +private:
 +};
 +
 +enum trace_type {
 +  
 +  TRACE_FIXED,                /*< Trace fixed, no availability file */
 +  TRACE_DYNAMIC               /*< Dynamic, availability file disponible */
 +};
 +
 +class CpuTiTgmr {
 +public:
 +  CpuTiTgmr(trace_type type, double value): m_type(type), m_value(value){};
 +  CpuTiTgmr(tmgr_trace_t power_trace, double value);
 +  ~CpuTiTgmr();
 +
 +  double integrate(double a, double b);
 +  double solve(double a, double amount);
 +  double solveSomewhatSimple(double a, double amount);
 +  double getPowerScale(double a);
 +
 +  trace_type m_type;
 +  double m_value;                 /*< Percentage of cpu power disponible. Value fixed between 0 and 1 */
 +
 +  /* Dynamic */
 +  double m_lastTime;             /*< Integral interval last point (discret time) */
 +  double m_total;                 /*< Integral total between 0 and last_pointn */
 +
 +  CpuTiTracePtr p_trace;
 +  tmgr_trace_t p_powerTrace;
 +};
 +
 +
 +/*********
 + * Model *
 + *********/
 +class CpuTiModel : public CpuModel {
 +public:
 +  CpuTiModel();
 +  ~CpuTiModel();
 +
 +  void parseInit(sg_platf_host_cbarg_t host);
-   CpuTi(CpuTiModelPtr model, const char *name, double powerPeak,
-         double powerScale, tmgr_trace_t powerTrace, int core,
++  CpuTiPtr createResource(const char *name,  xbt_dynar_t powerPeak,
++                          int pstate, double power_scale,
 +                          tmgr_trace_t power_trace, int core,
 +                          e_surf_resource_state_t state_initial,
 +                          tmgr_trace_t state_trace,
 +                          xbt_dict_t cpu_properties);
 +  CpuTiActionPtr createAction(double cost, bool failed);
 +  double shareResources(double now);
 +  void updateActionsState(double now, double delta);
 +  void addTraces();
 +
 +protected:
 +  void NotifyResourceTurnedOn(ResourcePtr r){};
 +  void NotifyResourceTurnedOff(ResourcePtr r){};
 +
 +  void NotifyActionCancel(ActionPtr a){};
 +  void NotifyActionResume(ActionPtr a){};
 +  void NotifyActionSuspend(ActionPtr a){};
 +};
 +
 +/************
 + * Resource *
 + ************/
 +class CpuTi : public Cpu {
 +public:
 +  CpuTi() {};
-   tmgr_trace_event_t p_powerEvent;       /*< trace file with availabitly events */
++  CpuTi(CpuTiModelPtr model, const char *name, xbt_dynar_t powerPeak,
++        int pstate, double powerScale, tmgr_trace_t powerTrace, int core,
 +        e_surf_resource_state_t stateInitial, tmgr_trace_t stateTrace,
 +      xbt_dict_t properties) ;
 +  ~CpuTi() {};
 +
 +  void updateState(tmgr_trace_event_t event_type, double value, double date);  
 +  void updateActionFinishDate(double now);
 +  bool isUsed();
 +  void printCpuTiModel();
 +  CpuActionPtr execute(double size);
 +  CpuTiActionPtr _execute(double size);
 +  CpuActionPtr sleep(double duration);
 +  double getAvailableSpeed();
 +
++  xbt_dynar_t getWattsRangeList() {};
++  double getCurrentWattsValue(double cpu_load) {};
++  void updateEnergy(double cpu_load) {};
++
++  double getCurrentPowerPeak() {};
++  double getPowerPeakAt(int pstate_index) {};
++  int getNbPstates() {};
++  void setPowerPeakAt(int pstate_index) {};
++  double getConsumedEnergy() {};
++
 +  CpuTiTgmrPtr p_availTrace;       /*< Structure with data needed to integrate trace file */
 +  tmgr_trace_event_t p_stateEvent;       /*< trace file with states events (ON or OFF) */
-   s_xbt_swag_hookup_t p_modifiedCpuHookup;      /*< hookup to swag that indicacates whether share resources must be recalculated or not */
++  tmgr_trace_event_t p_powerEvent;       /*< trace file with availability events */
 +  xbt_swag_t p_actionSet;        /*< set with all actions running on cpu */
++  s_xbt_swag_hookup_t p_modifiedCpuHookup;      /*< hookup to swag that indicates whether share resources must be recalculated or not */
 +  double m_sumPriority;          /*< the sum of actions' priority that are running on cpu */
 +  double m_lastUpdate;           /*< last update of actions' remaining amount done */
++
++  int m_pstate;                                                               /*< Current pstate (index in the power_peak_list)*/
++  double current_frequency;
++
 +  void updateRemainingAmount(double now);
 +};
 +
 +/**********
 + * Action *
 + **********/
 +
 +class CpuTiAction: public CpuAction {
 +public:
 +  CpuTiAction() {};
 +  CpuTiAction(CpuTiModelPtr model, double cost, bool failed)
 +  : Action(model, cost, failed), CpuAction(model, cost, failed) {
 +      p_cpuListHookup.next = 0;
 +      p_cpuListHookup.prev = 0;
 +  };
 +
 +  void setState(e_surf_action_state_t state);
 +  int unref();
 +  void cancel();
 +  void recycle();
 +  void updateIndexHeap(int i);
 +  void suspend();
 +  void resume();
 +  bool isSuspended();
 +  void setMaxDuration(double duration);
 +  void setPriority(double priority);
 +  double getRemains();
 +  CpuTiPtr p_cpu;
 +  int m_indexHeap;
 +  s_xbt_swag_hookup_t p_cpuListHookup;
 +  int m_suspended;
 +private:
 +};
diff --combined src/surf/instr_routing.c
@@@ -1,15 -1,14 +1,14 @@@
- /* Copyright (c) 2010. The SimGrid Team.
+ /* Copyright (c) 2010, 2012-2013. 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. */
  
  #include "instr/instr_private.h"
- #include "mc/mc.h"
  
  #ifdef HAVE_TRACING
  #include "surf/surf_private.h"
 -#include "surf/network_private.h"
 +//FIXME:#include "surf/network_private.h"
  #include "xbt/graph.h"
  
  XBT_LOG_NEW_DEFAULT_SUBCATEGORY (instr_routing, instr, "Tracing platform hierarchy");
@@@ -117,9 -116,6 +116,6 @@@ static void linkContainers (container_
    //create the link
    static long long counter = 0;
  
-   if(MC_is_active())
-     MC_ignore_data_bss(&counter, sizeof(counter));
    char key[INSTR_DEFAULT_STR_SIZE];
    snprintf (key, INSTR_DEFAULT_STR_SIZE, "%lld", counter++);
    new_pajeStartLink(SIMIX_get_clock(), father, link_type, src, "topology", key);
@@@ -134,14 -130,14 +130,14 @@@ static void recursiveGraphExtraction (A
      XBT_DEBUG("Graph extraction disabled by user.");
      return;
    }
 -  XBT_DEBUG ("Graph extraction for routing_component = %s", rc->name);
 -  if (!xbt_dict_is_empty(rc->routing_sons)){
 +  XBT_DEBUG ("Graph extraction for routing_component = %s", surf_AS_get_name(rc));
 +  if (!xbt_dict_is_empty(surf_AS_get_routing_sons(rc))){
      xbt_dict_cursor_t cursor = NULL;
      AS_t rc_son;
      char *child_name;
      //bottom-up recursion
 -    xbt_dict_foreach(rc->routing_sons, cursor, child_name, rc_son) {
 -      container_t child_container = xbt_dict_get (container->children, rc_son->name);
 +    xbt_dict_foreach(surf_AS_get_routing_sons(rc), cursor, child_name, rc_son) {
 +      container_t child_container = xbt_dict_get (container->children, surf_AS_get_name(rc_son));
        recursiveGraphExtraction (rc_son, child_container, filter);
      }
    }
      xbt_dict_cursor_t cursor = NULL;
      char *edge_name;
  
 -    rc->get_graph(graph,nodes,edges,rc);
 +    surf_AS_get_graph(rc, graph, nodes, edges);
      xbt_dict_foreach(edges,cursor,edge_name,edge) {
          linkContainers(PJ_container_get(edge->src->data), PJ_container_get(edge->dst->data), filter);
      }
@@@ -268,7 -264,10 +264,10 @@@ static void instr_routing_parse_start_h
      if (power == NULL){
        power = PJ_type_variable_new ("power", NULL, new->type);
      }
-     new_pajeSetVariable (0, new, power, host->power_peak);
+     double current_power_state;
+     xbt_dynar_get_cpy(host->power_peak, host->pstate, &current_power_state);
+     new_pajeSetVariable (0, new, power, current_power_state);
    }
    if (TRACE_uncategorized()){
      type_t power_used = PJ_type_get_or_null ("power_used", new->type);
@@@ -330,7 -329,7 +329,7 @@@ static void instr_routing_parse_end_pla
    currentContainer = NULL;
    xbt_dict_t filter = xbt_dict_new_homogeneous(xbt_free);
    XBT_DEBUG ("Starting graph extraction.");
 -  recursiveGraphExtraction (routing_platf->root, PJ_container_get_root(), filter);
 +  recursiveGraphExtraction (surf_platf_get_root(routing_platf), PJ_container_get_root(), filter);
    XBT_DEBUG ("Graph extraction finished.");
    xbt_dict_free(&filter);
    platform_created = 1;
@@@ -450,18 -449,18 +449,18 @@@ int instr_platform_traced (
  static void recursiveXBTGraphExtraction (xbt_graph_t graph, xbt_dict_t nodes, xbt_dict_t edges,
      AS_t rc, container_t container)
  {
 -  if (!xbt_dict_is_empty(rc->routing_sons)){
 +  if (!xbt_dict_is_empty(surf_AS_get_routing_sons(rc))){
      xbt_dict_cursor_t cursor = NULL;
      AS_t rc_son;
      char *child_name;
      //bottom-up recursion
 -    xbt_dict_foreach(rc->routing_sons, cursor, child_name, rc_son) {
 -      container_t child_container = xbt_dict_get (container->children, rc_son->name);
 +    xbt_dict_foreach(surf_AS_get_routing_sons(rc), cursor, child_name, rc_son) {
 +      container_t child_container = xbt_dict_get (container->children, surf_AS_get_name(rc_son));
        recursiveXBTGraphExtraction (graph, nodes, edges, rc_son, child_container);
      }
    }
  
 -  rc->get_graph(graph,nodes,edges,rc);
 +  surf_AS_get_graph(rc, graph, nodes, edges);
  }
  
  xbt_graph_t instr_routing_platform_graph (void)
    xbt_graph_t ret = xbt_graph_new_graph (0, NULL);
    xbt_dict_t nodes = xbt_dict_new_homogeneous(NULL);
    xbt_dict_t edges = xbt_dict_new_homogeneous(NULL);
 -  recursiveXBTGraphExtraction (ret, nodes, edges, routing_platf->root, PJ_container_get_root());
 +  recursiveXBTGraphExtraction (ret, nodes, edges, surf_platf_get_root(routing_platf), PJ_container_get_root());
    xbt_dict_free (&nodes);
    xbt_dict_free (&edges);
    return ret;
diff --combined src/surf/instr_surf.c
@@@ -1,4 -1,4 +1,4 @@@
- /* Copyright (c) 2010. The SimGrid Team.
+ /* Copyright (c) 2010, 2012. The SimGrid Team.
   * All rights reserved.                                                     */
  
  /* This program is free software; you can redistribute it and/or modify it
@@@ -6,7 -6,7 +6,7 @@@
  
  #include "instr/instr_private.h"
  #include "surf/surf_private.h"
 -#include "surf/network_gtnets_private.h"
 +//FIXME:#include "surf/network_gtnets_private.h"
  
  #ifdef HAVE_TRACING
  
@@@ -43,9 -43,9 +43,9 @@@ void TRACE_surf_link_set_bandwidth(doub
  /* to trace gtnets */
  void TRACE_surf_gtnets_communicate(void *action, void *src, void *dst)
  {
 -  surf_action_network_GTNETS_t gtnets_action = (surf_action_network_GTNETS_t)action;
 +  /*FIXME:surf_action_network_GTNETS_t gtnets_action = (surf_action_network_GTNETS_t)action;
    gtnets_action->src = src;
 -  gtnets_action->dst = dst;
 +  gtnets_action->dst = dst;*/
  }
  
  void TRACE_surf_action(surf_action_t surf_action, const char *category)
@@@ -57,6 -57,6 +57,6 @@@
    if (!category)
      return;
  
 -  surf_action->category = xbt_strdup(category);
 +  surf_action_set_category(surf_action, xbt_strdup(category));
  }
  #endif /* HAVE_TRACING */
diff --combined src/surf/network.cpp
index 23a4230,0000000..e8e886e
mode 100644,000000..100644
--- /dev/null
@@@ -1,698 -1,0 +1,698 @@@
-   /*   printf("[" "%lg" "] Asking to update network card \"%s\" with value " */
-   /*     "%lg" " for event %p\n", surf_get_clock(), nw_link->name, */
 +#include "network.hpp"
 +#include "maxmin_private.h"
 +#include "simgrid/sg_config.h"
 +
 +extern "C" {
 +XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_network, surf,
 +                                "Logging specific to the SURF network module");
 +}
 +
 +NetworkCm02ModelPtr surf_network_model = NULL;
 +
 +double sg_sender_gap = 0.0;
 +double sg_latency_factor = 1.0; /* default value; can be set by model or from command line */
 +double sg_bandwidth_factor = 1.0;       /* default value; can be set by model or from command line */
 +double sg_weight_S_parameter = 0.0;     /* default value; can be set by model or from command line */
 +
 +double sg_tcp_gamma = 0.0;
 +int sg_network_crosstraffic = 0;
 +
 +/*************
 + * CallBacks *
 + *************/
 +
 +static void net_parse_link_init(sg_platf_link_cbarg_t link){
 +  if (link->policy == SURF_LINK_FULLDUPLEX) {
 +    char *link_id;
 +    link_id = bprintf("%s_UP", link->id);
 +    surf_network_model->createResource(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);
 +    surf_network_model->createResource(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);
 +  } else {
 +      surf_network_model->createResource(link->id,
 +                      link->bandwidth,
 +                      link->bandwidth_trace,
 +                      link->latency,
 +                      link->latency_trace,
 +                      link->state,
 +                      link->state_trace, link->policy, link->properties);
 +  }
 +}
 +
 +static void net_add_traces(void){
 +  xbt_dict_cursor_t cursor = NULL;
 +  char *trace_name, *elm;
 +
 +  static int called = 0;
 +  if (called)
 +    return;
 +  called = 1;
 +
 +  /* connect all traces relative to network */
 +  xbt_dict_foreach(trace_connect_list_link_avail, cursor, trace_name, elm) {
 +    tmgr_trace_t trace = (tmgr_trace_t) xbt_dict_get_or_null(traces_set_list, trace_name);
 +    NetworkCm02LinkLmmPtr link = dynamic_cast<NetworkCm02LinkLmmPtr>(
 +                                   static_cast<ResourcePtr>(
 +                                                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);
 +    xbt_assert(trace,
 +               "Cannot connect trace %s to link %s: trace undefined",
 +               trace_name, elm);
 +
 +    link->p_stateEvent = tmgr_history_add_trace(history, trace, 0.0, 0, static_cast<ResourcePtr>(link));
 +  }
 +
 +  xbt_dict_foreach(trace_connect_list_bandwidth, cursor, trace_name, elm) {
 +    tmgr_trace_t trace = (tmgr_trace_t) xbt_dict_get_or_null(traces_set_list, trace_name);
 +    NetworkCm02LinkLmmPtr link = dynamic_cast<NetworkCm02LinkLmmPtr>(
 +                                 static_cast<ResourcePtr>(
 +                                            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);
 +    xbt_assert(trace,
 +               "Cannot connect trace %s to link %s: trace undefined",
 +               trace_name, elm);
 +
 +    link->p_power.event = tmgr_history_add_trace(history, trace, 0.0, 0, static_cast<ResourcePtr>(link));
 +  }
 +
 +  xbt_dict_foreach(trace_connect_list_latency, cursor, trace_name, elm) {
 +    tmgr_trace_t trace = (tmgr_trace_t) xbt_dict_get_or_null(traces_set_list, trace_name);
 +    NetworkCm02LinkLmmPtr link = dynamic_cast<NetworkCm02LinkLmmPtr>(
 +                                 static_cast<ResourcePtr>(
 +                                            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);
 +    xbt_assert(trace,
 +               "Cannot connect trace %s to link %s: trace undefined",
 +               trace_name, elm);
 +
 +    link->p_latEvent = tmgr_history_add_trace(history, trace, 0.0, 0, static_cast<ResourcePtr>(link));
 +  }
 +}
 +
 +void net_define_callbacks(void)
 +{
 +  /* Figuring out the network links */
 +  sg_platf_link_add_cb(net_parse_link_init);
 +  sg_platf_postparse_add_cb(net_add_traces);
 +}
 +
 +/*********
 + * Model *
 + *********/
 +
 +/************************************************************************/
 +/* New model based on optimizations discussed during Pedro Velho's thesis*/
 +/************************************************************************/
 +/* @techreport{VELHO:2011:HAL-00646896:1, */
 +/*      url = {http://hal.inria.fr/hal-00646896/en/}, */
 +/*      title = {{Flow-level network models: have we reached the limits?}}, */
 +/*      author = {Velho, Pedro and Schnorr, Lucas and Casanova, Henri and Legrand, Arnaud}, */
 +/*      type = {Rapport de recherche}, */
 +/*      institution = {INRIA}, */
 +/*      number = {RR-7821}, */
 +/*      year = {2011}, */
 +/*      month = Nov, */
 +/*      pdf = {http://hal.inria.fr/hal-00646896/PDF/rr-validity.pdf}, */
 +/*  } */
 +void surf_network_model_init_LegrandVelho(void)
 +{
 +  if (surf_network_model)
 +    return;
 +
 +  surf_network_model = new NetworkCm02Model();
 +  net_define_callbacks();
 +  ModelPtr model = static_cast<ModelPtr>(surf_network_model);
 +  xbt_dynar_push(model_list, &model);
 +
 +  xbt_cfg_setdefault_double(_sg_cfg_set, "network/latency_factor",
 +                            13.01);
 +  xbt_cfg_setdefault_double(_sg_cfg_set, "network/bandwidth_factor",
 +                            0.97);
 +  xbt_cfg_setdefault_double(_sg_cfg_set, "network/weight_S", 20537);
 +}
 +
 +/***************************************************************************/
 +/* The nice TCP sharing model designed by Loris Marchal and Henri Casanova */
 +/***************************************************************************/
 +/* @TechReport{      rr-lip2002-40, */
 +/*   author        = {Henri Casanova and Loris Marchal}, */
 +/*   institution   = {LIP}, */
 +/*   title         = {A Network Model for Simulation of Grid Application}, */
 +/*   number        = {2002-40}, */
 +/*   month         = {oct}, */
 +/*   year          = {2002} */
 +/* } */
 +void surf_network_model_init_CM02(void)
 +{
 +
 +  if (surf_network_model)
 +    return;
 +
 +  surf_network_model = new NetworkCm02Model();
 +  net_define_callbacks();
 +  ModelPtr model = static_cast<ModelPtr>(surf_network_model);
 +  xbt_dynar_push(model_list, &model);
 +
 +  xbt_cfg_setdefault_double(_sg_cfg_set, "network/latency_factor", 1.0);
 +  xbt_cfg_setdefault_double(_sg_cfg_set, "network/bandwidth_factor",
 +                            1.0);
 +  xbt_cfg_setdefault_double(_sg_cfg_set, "network/weight_S", 0.0);
 +}
 +
 +/***************************************************************************/
 +/* The models from Steven H. Low                                           */
 +/***************************************************************************/
 +/* @article{Low03,                                                         */
 +/*   author={Steven H. Low},                                               */
 +/*   title={A Duality Model of {TCP} and Queue Management Algorithms},     */
 +/*   year={2003},                                                          */
 +/*   journal={{IEEE/ACM} Transactions on Networking},                      */
 +/*    volume={11}, number={4},                                             */
 +/*  }                                                                      */
 +void surf_network_model_init_Reno(void)
 +{
 +  if (surf_network_model)
 +    return;
 +
 +  surf_network_model = new NetworkCm02Model();
 +  net_define_callbacks();
 +  ModelPtr model = static_cast<ModelPtr>(surf_network_model);
 +  xbt_dynar_push(model_list, &model);
 +  lmm_set_default_protocol_function(func_reno_f, func_reno_fp,
 +                                    func_reno_fpi);
 +  surf_network_model->f_networkSolve = lagrange_solve;
 +
 +  xbt_cfg_setdefault_double(_sg_cfg_set, "network/latency_factor", 10.4);
 +  xbt_cfg_setdefault_double(_sg_cfg_set, "network/bandwidth_factor",
 +                            0.92);
 +  xbt_cfg_setdefault_double(_sg_cfg_set, "network/weight_S", 8775);
 +}
 +
 +
 +void surf_network_model_init_Reno2(void)
 +{
 +  if (surf_network_model)
 +    return;
 +
 +  surf_network_model = new NetworkCm02Model();
 +  net_define_callbacks();
 +  ModelPtr model = static_cast<ModelPtr>(surf_network_model);
 +  xbt_dynar_push(model_list, &model);
 +  lmm_set_default_protocol_function(func_reno2_f, func_reno2_fp,
 +                                    func_reno2_fpi);
 +  surf_network_model->f_networkSolve = lagrange_solve;
 +
 +  xbt_cfg_setdefault_double(_sg_cfg_set, "network/latency_factor", 10.4);
 +  xbt_cfg_setdefault_double(_sg_cfg_set, "network/bandwidth_factor",
 +                            0.92);
 +  xbt_cfg_setdefault_double(_sg_cfg_set, "network/weight_S_parameter",
 +                            8775);
 +}
 +
 +void surf_network_model_init_Vegas(void)
 +{
 +  if (surf_network_model)
 +    return;
 +
 +  surf_network_model = new NetworkCm02Model();
 +  net_define_callbacks();
 +  ModelPtr model = static_cast<ModelPtr>(surf_network_model);
 +  xbt_dynar_push(model_list, &model);
 +  lmm_set_default_protocol_function(func_vegas_f, func_vegas_fp,
 +                                    func_vegas_fpi);
 +  surf_network_model->f_networkSolve = lagrange_solve;
 +
 +  xbt_cfg_setdefault_double(_sg_cfg_set, "network/latency_factor", 10.4);
 +  xbt_cfg_setdefault_double(_sg_cfg_set, "network/bandwidth_factor",
 +                            0.92);
 +  xbt_cfg_setdefault_double(_sg_cfg_set, "network/weight_S", 8775);
 +}
 +
 +NetworkCm02Model::NetworkCm02Model() : NetworkCm02Model("network"){
 +}
 +
 +NetworkCm02Model::NetworkCm02Model(string name) : Model(name){
 +  ActionLmmPtr comm;
 +
 +  char *optim = xbt_cfg_get_string(_sg_cfg_set, "network/optim");
 +  int select =
 +      xbt_cfg_get_boolean(_sg_cfg_set, "network/maxmin_selective_update");
 +
 +  if (!strcmp(optim, "Full")) {
 +    p_updateMechanism = UM_FULL;
 +    m_selectiveUpdate = select;
 +  } else if (!strcmp(optim, "Lazy")) {
 +    p_updateMechanism = UM_LAZY;
 +    m_selectiveUpdate = 1;
 +    xbt_assert((select == 1)
 +               ||
 +               (xbt_cfg_is_default_value
 +                (_sg_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);
 +  }
 +
 +  if (!p_maxminSystem)
 +      p_maxminSystem = lmm_system_new(m_selectiveUpdate);
 +
 +  routing_model_create(static_cast<ResourcePtr>(createResource("__loopback__",
 +                                                 498000000, NULL, 0.000015, NULL,
 +                                                 SURF_RESOURCE_ON, NULL,
 +                                                 SURF_LINK_FATPIPE, NULL)));
 +
 +  if (p_updateMechanism == UM_LAZY) {
 +      p_actionHeap = xbt_heap_new(8, NULL);
 +      xbt_heap_set_update_callback(p_actionHeap, surf_action_lmm_update_index_heap);
 +      p_modifiedSet = xbt_swag_new(xbt_swag_offset(*comm, p_actionListHookup));
 +      p_maxminSystem->keep_track = p_modifiedSet;
 +  }
 +}
 +
 +NetworkCm02LinkLmmPtr NetworkCm02Model::createResource(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)
 +{
 +  xbt_assert(!xbt_lib_get_or_null(link_lib, name, SURF_LINK_LEVEL),
 +             "Link '%s' declared several times in the platform file.",
 +             name);
 +
 +  NetworkCm02LinkLmmPtr nw_link =
 +                new NetworkCm02LinkLmm(this, name, properties, p_maxminSystem, sg_bandwidth_factor * bw_initial, history,
 +                                               state_initial, state_trace, bw_initial, bw_trace, lat_initial, lat_trace, policy);
 +
 +
 +  xbt_lib_set(link_lib, name, SURF_LINK_LEVEL, static_cast<ResourcePtr>(nw_link));
 +  XBT_DEBUG("Create link '%s'",name);
 +
 +  return nw_link;
 +}
 +
 +void NetworkCm02Model::updateActionsStateLazy(double now, double delta)
 +{
 +  NetworkCm02ActionLmmPtr action;
 +  while ((xbt_heap_size(p_actionHeap) > 0)
 +         && (double_equals(xbt_heap_maxkey(p_actionHeap), now))) {
 +    action = (NetworkCm02ActionLmmPtr) xbt_heap_pop(p_actionHeap);
 +    XBT_DEBUG("Something happened to action %p", action);
 +#ifdef HAVE_TRACING
 +    if (TRACE_is_enabled()) {
 +      int n = lmm_get_number_of_cnst_from_var(p_maxminSystem, action->p_variable);
 +      unsigned int i;
 +      for (i = 0; i < n; i++){
 +        lmm_constraint_t constraint = lmm_get_cnst_from_var(p_maxminSystem,
 +                                                            action->p_variable,
 +                                                            i);
 +        NetworkCm02LinkPtr link = static_cast<NetworkCm02LinkPtr>(lmm_constraint_id(constraint));
 +        TRACE_surf_link_set_utilization(link->m_name,
 +                                        action->p_category,
 +                                        (lmm_variable_getvalue(action->p_variable)*
 +                                            lmm_get_cnst_weight_from_var(p_maxminSystem,
 +                                                action->p_variable,
 +                                                i)),
 +                                        action->m_lastUpdate,
 +                                        now - action->m_lastUpdate);
 +      }
 +    }
 +#endif
 +
 +    // if I am wearing a latency hat
 +    if (action->m_hat == LATENCY) {
 +      XBT_DEBUG("Latency paid for action %p. Activating", action);
 +      lmm_update_variable_weight(p_maxminSystem, action->p_variable, action->m_weight);
 +      action->heapRemove(p_actionHeap);
 +      action->m_lastUpdate = surf_get_clock();
 +
 +        // if I am wearing a max_duration or normal hat
 +    } else if (action->m_hat == MAX_DURATION ||
 +        action->m_hat == NORMAL) {
 +        // no need to communicate anymore
 +        // assume that flows that reached max_duration have remaining of 0
 +      action->m_finish = surf_get_clock();
 +      XBT_DEBUG("Action %p finished", action);
 +      action->m_remains = 0;
 +      action->m_finish = surf_get_clock();
 +      action->setState(SURF_ACTION_DONE);
 +      action->heapRemove(p_actionHeap);
 +
 +      action->gapRemove();
 +    }
 +  }
 +  return;
 +}
 +
 +xbt_dynar_t NetworkCm02Model::getRoute(RoutingEdgePtr src, RoutingEdgePtr dst)
 +{
 +  xbt_dynar_t route = NULL;
 +  routing_platf->getRouteAndLatency(src, dst, &route, NULL);
 +  return route;
 +}
 +
 +ActionPtr NetworkCm02Model::communicate(RoutingEdgePtr src, RoutingEdgePtr dst,
 +                                                double size, double rate)
 +{
 +  unsigned int i;
 +  void *_link;
 +  NetworkCm02LinkLmmPtr link;
 +  int failed = 0;
 +  NetworkCm02ActionLmmPtr action = NULL;
 +  double bandwidth_bound;
 +  double latency = 0.0;
 +  xbt_dynar_t back_route = NULL;
 +  int constraints_per_variable = 0;
 +
 +  xbt_dynar_t route = xbt_dynar_new(sizeof(RoutingEdgePtr), NULL);
 +
 +  XBT_IN("(%s,%s,%g,%g)", src->p_name, dst->p_name, size, rate);
 +
 +  routing_platf->getRouteAndLatency(src, dst, &route, &latency);
 +  xbt_assert(!xbt_dynar_is_empty(route) || latency,
 +             "You're trying to send data from %s to %s but there is no connection at all between these two hosts.",
 +             src->p_name, dst->p_name);
 +
 +  xbt_dynar_foreach(route, i, _link) {
 +      link = dynamic_cast<NetworkCm02LinkLmmPtr>(static_cast<ResourcePtr>(_link));
 +    if (link->p_stateCurrent == SURF_RESOURCE_OFF) {
 +      failed = 1;
 +      break;
 +    }
 +  }
 +  if (sg_network_crosstraffic == 1) {
 +        routing_platf->getRouteAndLatency(dst, src, &back_route, NULL);
 +    xbt_dynar_foreach(back_route, i, _link) {
 +      link = dynamic_cast<NetworkCm02LinkLmmPtr>(static_cast<ResourcePtr>(_link));
 +      if (link->p_stateCurrent == SURF_RESOURCE_OFF) {
 +        failed = 1;
 +        break;
 +      }
 +    }
 +  }
 +
 +  action = new NetworkCm02ActionLmm(this, size, failed);
 +
 +#ifdef HAVE_LATENCY_BOUND_TRACKING
 +  action->m_latencyLimited = 0;
 +#endif
 +  action->m_weight = action->m_latency = latency;
 +
 +  //FIXME:REMOVxbt_swag_insert(action, action->p_stateSet);
 +  action->m_rate = rate;
 +  if (p_updateMechanism == UM_LAZY) {
 +    action->m_indexHeap = -1;
 +    action->m_lastUpdate = surf_get_clock();
 +  }
 +
 +  bandwidth_bound = -1.0;
 +  if (sg_weight_S_parameter > 0) {
 +    xbt_dynar_foreach(route, i, _link) {
 +      link = dynamic_cast<NetworkCm02LinkLmmPtr>(static_cast<ResourcePtr>(_link));
 +      action->m_weight +=
 +         sg_weight_S_parameter /
 +         (link->p_power.peak * link->p_power.scale);
 +    }
 +  }
 +  xbt_dynar_foreach(route, i, _link) {
 +      link = dynamic_cast<NetworkCm02LinkLmmPtr>(static_cast<ResourcePtr>(_link));
 +    double bb = bandwidthFactor(size) * (link->p_power.peak * link->p_power.scale);
 +    bandwidth_bound =
 +        (bandwidth_bound < 0.0) ? bb : min(bandwidth_bound, bb);
 +  }
 +
 +  action->m_latCurrent = action->m_latency;
 +  action->m_latency *= latencyFactor(size);
 +  action->m_rate = bandwidthConstraint(action->m_rate, bandwidth_bound, size);
 +  if (m_haveGap) {
 +    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 = *(NetworkCm02LinkLmmPtr *) xbt_dynar_get_ptr(route, 0);
 +    link = dynamic_cast<NetworkCm02LinkLmmPtr>(*static_cast<ResourcePtr *>(xbt_dynar_get_ptr(route, 0)));
 +    gapAppend(size, link, action);
 +    XBT_DEBUG("Comm %p: %s -> %s gap=%f (lat=%f)",
 +              action, src->p_name, dst->p_name, action->m_senderGap,
 +              action->m_latency);
 +  }
 +
 +  constraints_per_variable = xbt_dynar_length(route);
 +  if (back_route != NULL)
 +    constraints_per_variable += xbt_dynar_length(back_route);
 +
 +  if (action->m_latency > 0) {
 +    action->p_variable = lmm_variable_new(p_maxminSystem, action, 0.0, -1.0,
 +                         constraints_per_variable);
 +    if (p_updateMechanism == 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->m_latency + action->m_lastUpdate);
 +      action->heapInsert(p_actionHeap, action->m_latency + action->m_lastUpdate, xbt_dynar_is_empty(route) ? NORMAL : LATENCY);
 +    }
 +  } else
 +    action->p_variable = lmm_variable_new(p_maxminSystem, action, 1.0, -1.0, constraints_per_variable);
 +
 +  if (action->m_rate < 0) {
 +    lmm_update_variable_bound(p_maxminSystem, action->p_variable, (action->m_latCurrent > 0) ? sg_tcp_gamma / (2.0 * action->m_latCurrent) : -1.0);
 +  } else {
 +    lmm_update_variable_bound(p_maxminSystem, action->p_variable, (action->m_latCurrent > 0) ? min(action->m_rate, sg_tcp_gamma / (2.0 * action->m_latCurrent)) : action->m_rate);
 +  }
 +
 +  xbt_dynar_foreach(route, i, _link) {
 +      link = dynamic_cast<NetworkCm02LinkLmmPtr>(static_cast<ResourcePtr>(_link));
 +    lmm_expand(p_maxminSystem, link->p_constraint, action->p_variable, 1.0);
 +  }
 +
 +  if (sg_network_crosstraffic == 1) {
 +    XBT_DEBUG("Fullduplex active adding backward flow using 5%%");
 +    xbt_dynar_foreach(back_route, i, _link) {
 +      link = dynamic_cast<NetworkCm02LinkLmmPtr>(static_cast<ResourcePtr>(_link));
 +      lmm_expand(p_maxminSystem, link->p_constraint, action->p_variable, .05);
 +    }
 +  }
 +
 +  xbt_dynar_free(&route);
 +  XBT_OUT();
 +
 +  return action;
 +}
 +
 +double NetworkCm02Model::latencyFactor(double size) {
 +  return sg_latency_factor;
 +}
 +
 +double NetworkCm02Model::bandwidthFactor(double size) {
 +  return sg_bandwidth_factor;
 +}
 +
 +double NetworkCm02Model::bandwidthConstraint(double rate, double bound, double size) {
 +  return rate;
 +}
 +
 +/************
 + * Resource *
 + ************/
 +NetworkCm02LinkLmm::NetworkCm02LinkLmm(NetworkCm02ModelPtr model, const char *name, xbt_dict_t props,
 +                                 lmm_system_t system,
 +                                 double constraint_value,
 +                                 tmgr_history_t history,
 +                                 e_surf_resource_state_t state_init,
 +                                 tmgr_trace_t state_trace,
 +                                 double metric_peak,
 +                                 tmgr_trace_t metric_trace,
 +                                 double lat_initial,
 +                                 tmgr_trace_t lat_trace,
 +                                 e_surf_link_sharing_policy_t policy)
 +: Resource(model, name, props),
 +  ResourceLmm(model, name, props, system, constraint_value, history, state_init, state_trace, metric_peak, metric_trace),
 +  NetworkCm02Link(model, name, props)
 +{
 +  m_latCurrent = lat_initial;
 +  if (lat_trace)
 +      p_latEvent = tmgr_history_add_trace(history, lat_trace, 0.0, 0, static_cast<ResourcePtr>(this));
 +
 +  if (policy == SURF_LINK_FATPIPE)
 +      lmm_constraint_shared(p_constraint);
 +}
 +
 +bool NetworkCm02LinkLmm::isUsed()
 +{
 +  return lmm_constraint_used(p_model->p_maxminSystem, p_constraint);
 +}
 +
 +double NetworkCm02Link::getLatency()
 +{
 +  return m_latCurrent;
 +}
 +
 +double NetworkCm02LinkLmm::getBandwidth()
 +{
 +  return p_power.peak * p_power.scale;
 +}
 +
 +bool NetworkCm02LinkLmm::isShared()
 +{
 +  return lmm_constraint_is_shared(p_constraint);
 +}
 +
 +void NetworkCm02LinkLmm::updateState(tmgr_trace_event_t event_type,
 +                                      double value, double date)
 +{
++  /*   printf("[" "%g" "] Asking to update network card \"%s\" with value " */
++  /*     "%g" " for event %p\n", surf_get_clock(), nw_link->name, */
 +  /*     value, event_type); */
 +
 +  if (event_type == p_power.event) {
 +    double delta =
 +        sg_weight_S_parameter / value - sg_weight_S_parameter /
 +        (p_power.peak * p_power.scale);
 +    lmm_variable_t var = NULL;
 +    lmm_element_t elem = NULL;
 +    NetworkCm02ActionLmmPtr action = NULL;
 +
 +    p_power.peak = value;
 +    lmm_update_constraint_bound(p_model->p_maxminSystem,
 +                                p_constraint,
 +                                sg_bandwidth_factor *
 +                                (p_power.peak * p_power.scale));
 +#ifdef HAVE_TRACING
 +    TRACE_surf_link_set_bandwidth(date, m_name, sg_bandwidth_factor * p_power.peak * p_power.scale);
 +#endif
 +    if (sg_weight_S_parameter > 0) {
 +      while ((var = lmm_get_var_from_cnst(p_model->p_maxminSystem, p_constraint, &elem))) {
 +        action = (NetworkCm02ActionLmmPtr) lmm_variable_id(var);
 +        action->m_weight += delta;
 +        if (!action->m_suspended)
 +          lmm_update_variable_weight(p_model->p_maxminSystem, action->p_variable, action->m_weight);
 +      }
 +    }
 +    if (tmgr_trace_event_free(event_type))
 +      p_power.event = NULL;
 +  } else if (event_type == p_latEvent) {
 +    double delta = value - m_latCurrent;
 +    lmm_variable_t var = NULL;
 +    lmm_element_t elem = NULL;
 +    NetworkCm02ActionLmmPtr action = NULL;
 +
 +    m_latCurrent = value;
 +    while ((var = lmm_get_var_from_cnst(p_model->p_maxminSystem, p_constraint, &elem))) {
 +      action = (NetworkCm02ActionLmmPtr) lmm_variable_id(var);
 +      action->m_latCurrent += delta;
 +      action->m_weight += delta;
 +      if (action->m_rate < 0)
 +        lmm_update_variable_bound(p_model->p_maxminSystem, action->p_variable, sg_tcp_gamma / (2.0 * action->m_latCurrent));
 +      else {
 +        lmm_update_variable_bound(p_model->p_maxminSystem, action->p_variable,
 +                                  min(action->m_rate, sg_tcp_gamma / (2.0 * action->m_latCurrent)));
 +
 +        if (action->m_rate < sg_tcp_gamma / (2.0 * action->m_latCurrent)) {
 +          XBT_INFO("Flow is limited BYBANDWIDTH");
 +        } else {
 +          XBT_INFO("Flow is limited BYLATENCY, latency of flow is %f",
 +                   action->m_latCurrent);
 +        }
 +      }
 +      if (!action->m_suspended)
 +        lmm_update_variable_weight(p_model->p_maxminSystem, action->p_variable, action->m_weight);
 +
 +    }
 +    if (tmgr_trace_event_free(event_type))
 +      p_latEvent = NULL;
 +  } else if (event_type == p_stateEvent) {
 +    if (value > 0)
 +      p_stateCurrent = SURF_RESOURCE_ON;
 +    else {
 +      lmm_constraint_t cnst = p_constraint;
 +      lmm_variable_t var = NULL;
 +      lmm_element_t elem = NULL;
 +
 +      p_stateCurrent = SURF_RESOURCE_OFF;
 +      while ((var = lmm_get_var_from_cnst(p_model->p_maxminSystem, cnst, &elem))) {
 +        ActionPtr action = (ActionPtr) lmm_variable_id(var);
 +
 +        if (action->getState() == SURF_ACTION_RUNNING ||
 +            action->getState() == SURF_ACTION_READY) {
 +          action->m_finish = date;
 +          action->setState(SURF_ACTION_FAILED);
 +        }
 +      }
 +    }
 +    if (tmgr_trace_event_free(event_type))
 +      p_stateEvent = NULL;
 +  } else {
 +    XBT_CRITICAL("Unknown event ! \n");
 +    xbt_abort();
 +  }
 +
 +  XBT_DEBUG
 +      ("There were a resource state event, need to update actions related to the constraint (%p)",
 +       p_constraint);
 +  return;
 +}
 +
 +/**********
 + * Action *
 + **********/
 +void NetworkCm02ActionLmm::updateRemainingLazy(double now)
 +{
 +  double delta = 0.0;
 +
 +  if (m_suspended != 0)
 +    return;
 +
 +  delta = now - m_lastUpdate;
 +
 +  if (m_remains > 0) {
 +    XBT_DEBUG("Updating action(%p): remains was %lf, last_update was: %lf", this, m_remains, m_lastUpdate);
 +    double_update(&(m_remains), m_lastValue * delta);
 +
 +    XBT_DEBUG("Updating action(%p): remains is now %lf", this, m_remains);
 +  }
 +
 +  if (m_maxDuration != NO_MAX_DURATION)
 +    double_update(&m_maxDuration, delta);
 +
 +  if (m_remains <= 0 &&
 +      (lmm_get_variable_weight(p_variable) > 0)) {
 +    m_finish = surf_get_clock();
 +    setState(SURF_ACTION_DONE);
 +
 +    heapRemove(p_model->p_actionHeap);
 +  } else if (((m_maxDuration != NO_MAX_DURATION)
 +      && (m_maxDuration <= 0))) {
 +    m_finish = surf_get_clock();
 +    setState(SURF_ACTION_DONE);
 +    heapRemove(p_model->p_actionHeap);
 +  }
 +
 +  m_lastUpdate = now;
 +  m_lastValue = lmm_variable_getvalue(p_variable);
 +}
 +void NetworkCm02ActionLmm::recycle()
 +{
 +  return;
 +}
 +
index 6b177d6,0000000..13fff27
mode 100644,000000..100644
--- /dev/null
@@@ -1,172 -1,0 +1,168 @@@
- static random_data_t random_latency = NULL;
 +#include "network_constant.hpp"
 +#include "surf/random_mgr.h"
 +
 +XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(surf_network);
-   if (!random_latency)
-     random_latency = random_new(RAND, 100, 0.0, 1.0, .125, .034);
 +static int host_number_int = 0;
 +
 +static void netcste_count_hosts(sg_platf_host_cbarg_t h) {
 +  host_number_int++;
 +}
 +
 +/*********
 + * Model *
 + *********/
 +void surf_network_model_init_Constant()
 +{
 +  xbt_assert(surf_network_model == NULL);
 +  surf_network_model = new NetworkConstantModel();
 +
 +  sg_platf_host_add_cb(netcste_count_hosts);
 +
 +  ModelPtr model = static_cast<ModelPtr>(surf_network_model);
 +  xbt_dynar_push(model_list, &model);
 +
 +  routing_model_create(NULL);
 +}
 +
 +double NetworkConstantModel::shareResources(double now)
 +{
 +  void *_action = NULL;
 +  NetworkConstantActionLmmPtr action = NULL;
 +  double min = -1.0;
 +
 +  xbt_swag_foreach(_action, p_runningActionSet) {
 +      action = dynamic_cast<NetworkConstantActionLmmPtr>(static_cast<ActionPtr>(_action));
 +    if (action->m_latency > 0) {
 +      if (min < 0)
 +        min = action->m_latency;
 +      else if (action->m_latency < min)
 +        min = action->m_latency;
 +    }
 +  }
 +
 +  return min;
 +}
 +
 +void NetworkConstantModel::updateActionsState(double now, double delta)
 +{
 +  void *_action, *_next_action;
 +  NetworkConstantActionLmmPtr action = NULL;
 +
 +  xbt_swag_foreach_safe(_action, _next_action, p_runningActionSet) {
 +      action = dynamic_cast<NetworkConstantActionLmmPtr>(static_cast<ActionPtr>(_action));
 +    if (action->m_latency > 0) {
 +      if (action->m_latency > delta) {
 +        double_update(&(action->m_latency), delta);
 +      } else {
 +        action->m_latency = 0.0;
 +      }
 +    }
 +    double_update(&(action->m_remains),
 +                  action->m_cost * delta / action->m_latInit);
 +    if (action->m_maxDuration != NO_MAX_DURATION)
 +      double_update(&(action->m_maxDuration), delta);
 +
 +    if (action->m_remains <= 0) {
 +      action->m_finish = surf_get_clock();
 +      action->setState(SURF_ACTION_DONE);
 +    } else if ((action->m_maxDuration != NO_MAX_DURATION)
 +               && (action->m_maxDuration <= 0)) {
 +      action->m_finish = surf_get_clock();
 +      action->setState(SURF_ACTION_DONE);
 +    }
 +  }
 +}
 +
 +ActionPtr NetworkConstantModel::communicate(RoutingEdgePtr src, RoutingEdgePtr dst,
 +                                       double size, double rate)
 +{
 +  char *src_name = src->p_name;
 +  char *dst_name = dst->p_name;
 +
 +  XBT_IN("(%s,%s,%g,%g)", src_name, dst_name, size, rate);
 +  NetworkConstantActionLmmPtr action = new NetworkConstantActionLmm(this, sg_latency_factor);
 +  XBT_OUT();
 +
 +  return action;
 +}
 +
 +/************
 + * Resource *
 + ************/
 +bool NetworkConstantLinkLmm::isUsed()
 +{
 +  return 0;
 +}
 +
 +void NetworkConstantLinkLmm::updateState(tmgr_trace_event_t event_type,
 +                                      double value, double time)
 +{
 +  DIE_IMPOSSIBLE;
 +}
 +
 +double NetworkConstantLinkLmm::getBandwidth()
 +{
 +  DIE_IMPOSSIBLE;
 +  return -1.0; /* useless since DIE actually abort(), but eclipse prefer to have a useless and harmless return */
 +}
 +
 +double NetworkConstantLinkLmm::getLatency()
 +{
 +  DIE_IMPOSSIBLE;
 +  return -1.0; /* useless since DIE actually abort(), but eclipse prefer to have a useless and harmless return */
 +}
 +
 +bool NetworkConstantLinkLmm::isShared()
 +{
 +  DIE_IMPOSSIBLE;
 +  return -1; /* useless since DIE actually abort(), but eclipse prefer to have a useless and harmless return */
 +}
 +
 +/**********
 + * Action *
 + **********/
 +
 +int NetworkConstantActionLmm::unref()
 +{
 +  m_refcount--;
 +  if (!m_refcount) {
 +    xbt_swag_remove(static_cast<ActionPtr>(this), p_stateSet);
 +    delete this;
 +  return 1;
 +  }
 +  return 0;
 +}
 +
 +void NetworkConstantActionLmm::cancel()
 +{
 +  return;
 +}
 +
 +#ifdef HAVE_TRACING
 +void NetworkConstantActionLmm::setCategory(const char *category)
 +{
 +  //ignore completely the categories in constant model, they are not traced
 +}
 +#endif
 +
 +void NetworkConstantActionLmm::suspend()
 +{
 +  m_suspended = true;
 +}
 +
 +void NetworkConstantActionLmm::resume()
 +{
 +  if (m_suspended)
 +      m_suspended = false;
 +}
 +
 +void NetworkConstantActionLmm::recycle()
 +{
 +  return;
 +}
 +
 +bool NetworkConstantActionLmm::isSuspended()
 +{
 +  return m_suspended;
 +}
 +
index b38b3fe,0000000..ee6e415
mode 100644,000000..100644
--- /dev/null
@@@ -1,197 -1,0 +1,197 @@@
-       gap_lookup = xbt_dict_new();
 +#include "network_smpi.hpp"
 +#include "simgrid/sg_config.h"
 +
 +XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(surf_network);
 +
 +xbt_dynar_t smpi_bw_factor = NULL;
 +xbt_dynar_t smpi_lat_factor = NULL;
 +
 +typedef struct s_smpi_factor *smpi_factor_t;
 +typedef struct s_smpi_factor {
 +  long factor;
 +  double value;
 +} s_smpi_factor_t;
 +
 +xbt_dict_t gap_lookup = NULL;
 +
 +static int factor_cmp(const void *pa, const void *pb)
 +{
 +  return (((s_smpi_factor_t*)pa)->factor > ((s_smpi_factor_t*)pb)->factor);
 +}
 +
 +
 +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);
 +  iter=0;
 +  xbt_dynar_sort(smpi_factor, &factor_cmp);
 +  xbt_dynar_foreach(smpi_factor, iter, fact) {
 +    XBT_DEBUG("ordered smpi_factor:\t%ld : %f", fact.factor, fact.value);
 +
 +  }
 +  return smpi_factor;
 +}
 +
 +/*********
 + * Model *
 + *********/
 +
 +/************************************************************************/
 +/* New model based on LV08 and experimental results of MPI ping-pongs   */
 +/************************************************************************/
 +/* @Inproceedings{smpi_ipdps, */
 +/*  author={Pierre-Nicolas Clauss and Mark Stillwell and Stéphane Genaud and Frédéric Suter and Henri Casanova and Martin Quinson}, */
 +/*  title={Single Node On-Line Simulation of {MPI} Applications with SMPI}, */
 +/*  booktitle={25th IEEE International Parallel and Distributed Processing Symposium (IPDPS'11)}, */
 +/*  address={Anchorage (Alaska) USA}, */
 +/*  month=may, */
 +/*  year={2011} */
 +/*  } */
 +void surf_network_model_init_SMPI(void)
 +{
 +
 +  if (surf_network_model)
 +    return;
 +  surf_network_model = new NetworkSmpiModel();
 +  net_define_callbacks();
 +  xbt_dynar_push(model_list, &surf_network_model);
 +  //network_solve = lmm_solve;
 +
 +  xbt_cfg_setdefault_double(_sg_cfg_set, "network/sender_gap", 10e-6);
 +  xbt_cfg_setdefault_double(_sg_cfg_set, "network/weight_S", 8775);
 +}
 +
 +void NetworkSmpiModel::gapAppend(double size, const NetworkCm02LinkLmmPtr link, NetworkCm02ActionLmmPtr action)
 +{
 +  const char *src = link->m_name;
 +  xbt_fifo_t fifo;
 +  //surf_action_network_CM02_t last_action;
 +  //double bw;
 +
 +  if (sg_sender_gap > 0.0) {
 +    if (!gap_lookup) {
-       XBT_DEBUG("%lf <= %ld return %f", size, fact.factor, current);
++      gap_lookup = xbt_dict_new_homogeneous(NULL);
 +    }
 +    fifo = (xbt_fifo_t) xbt_dict_get_or_null(gap_lookup, src);
 +    action->m_senderGap = 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->m_senderGap = sg_sender_gap;
 +        /*  max(sg_sender_gap,last_action->sender.size / bw);*/
 +      action->m_latency += action->m_senderGap;
 +    }
 +    /* 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->m_senderSize = size;
 +  }
 +}
 +
 +void NetworkSmpiModel::gapRemove(ActionLmmPtr lmm_action)
 +{
 +  xbt_fifo_t fifo;
 +  size_t size;
 +  NetworkCm02ActionLmmPtr action = (NetworkCm02ActionLmmPtr)(lmm_action);
 +
 +  if (sg_sender_gap > 0.0 && action->p_senderLinkName
 +      && action->p_senderFifoItem) {
 +    fifo =
 +        (xbt_fifo_t) xbt_dict_get_or_null(gap_lookup,
 +                                          action->p_senderLinkName);
 +    xbt_fifo_remove_item(fifo, action->p_senderFifoItem);
 +    size = xbt_fifo_size(fifo);
 +    if (size == 0) {
 +      xbt_fifo_free(fifo);
 +      xbt_dict_remove(gap_lookup, action->p_senderLinkName);
 +      size = xbt_dict_length(gap_lookup);
 +      if (size == 0) {
 +        xbt_dict_free(&gap_lookup);
 +      }
 +    }
 +  }
 +}
 +
 +double NetworkSmpiModel::bandwidthFactor(double size)
 +{
 +  if (!smpi_bw_factor)
 +    smpi_bw_factor =
 +        parse_factor(sg_cfg_get_string("smpi/bw_factor"));
 +
 +  unsigned int iter = 0;
 +  s_smpi_factor_t fact;
 +  double current=1.0;
 +  xbt_dynar_foreach(smpi_bw_factor, iter, fact) {
 +    if (size <= fact.factor) {
-   XBT_DEBUG("%lf > %ld return %f", size, fact.factor, current);
++      XBT_DEBUG("%f <= %ld return %f", size, fact.factor, current);
 +      return current;
 +    }else
 +      current=fact.value;
 +  }
-       XBT_DEBUG("%lf <= %ld return %f", size, fact.factor, current);
++  XBT_DEBUG("%f > %ld return %f", size, fact.factor, current);
 +
 +  return current;
 +}
 +double NetworkSmpiModel::latencyFactor(double size)
 +{
 +  if (!smpi_lat_factor)
 +    smpi_lat_factor =
 +        parse_factor(sg_cfg_get_string("smpi/lat_factor"));
 +
 +  unsigned int iter = 0;
 +  s_smpi_factor_t fact;
 +  double current=1.0;
 +  xbt_dynar_foreach(smpi_lat_factor, iter, fact) {
 +    if (size <= fact.factor) {
-   XBT_DEBUG("%lf > %ld return %f", size, fact.factor, current);
++      XBT_DEBUG("%f <= %ld return %f", size, fact.factor, current);
 +      return current;
 +    }else
 +      current=fact.value;
 +  }
++  XBT_DEBUG("%f > %ld return %f", size, fact.factor, current);
 +
 +  return current;
 +}
 +
 +double NetworkSmpiModel::bandwidthConstraint(double rate, double bound, double size)
 +{
 +  return rate < 0 ? bound : min(bound, rate * bandwidthFactor(size));
 +}
 +
 +/************
 + * Resource *
 + ************/
 +
 +
 +
 +/**********
 + * Action *
 + **********/
diff --combined src/surf/storage.cpp
index 7a28858,0000000..1244418
mode 100644,000000..100644
--- /dev/null
@@@ -1,646 -1,0 +1,702 @@@
-   StoragePtr storage = (StoragePtr) r;
 +#include "storage.hpp"
 +#include "surf_private.h"
 +
++#define __STDC_FORMAT_MACROS
++#include <inttypes.h>
++
 +extern "C" {
 +XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_storage, surf,
 +                                "Logging specific to the SURF storage module");
 +}
 +
 +xbt_lib_t storage_lib;
 +int ROUTING_STORAGE_LEVEL;      //Routing for storagelevel
 +int ROUTING_STORAGE_HOST_LEVEL;
 +int SURF_STORAGE_LEVEL;
 +xbt_lib_t storage_type_lib;
 +int ROUTING_STORAGE_TYPE_LEVEL; //Routing for storage_type level
 +
 +static xbt_dynar_t storage_list;
 +
 +xbt_dynar_t mount_list = NULL;  /* temporary store of current mount storage */
 +StorageModelPtr surf_storage_model = NULL;
 +
 +static int storage_selective_update = 0;
 +static xbt_swag_t storage_running_action_set_that_does_not_need_being_checked = NULL;
 +
 +/*************
 + * CallBacks *
 + *************/
 +
 +static XBT_INLINE void routing_storage_type_free(void *r)
 +{
 +  storage_type_t stype = (storage_type_t) r;
 +  free(stype->model);
 +  free(stype->type_id);
 +  free(stype->content);
 +  xbt_dict_free(&(stype->properties));
++  xbt_dict_free(&(stype->properties));
 +  free(stype);
 +}
 +
 +static XBT_INLINE void surf_storage_resource_free(void *r)
 +{
 +  // specific to storage
-     XBT_DEBUG("For disk '%s' content is empty, use the content of storage type '%s'",storage->id,((storage_type_t) stype)->type_id);
++  StoragePtr storage = dynamic_cast<StoragePtr>(static_cast<ResourcePtr>(r));
 +  xbt_dict_free(&storage->p_content);
 +  xbt_dynar_free(&storage->p_writeActions);
++  free(storage->p_typeId);
++  free(storage->p_contentType);
 +  // generic resource
 +  delete storage;
 +}
 +
 +static XBT_INLINE void routing_storage_host_free(void *r)
 +{
 +  xbt_dynar_t dyn = (xbt_dynar_t) r;
 +  xbt_dynar_free(&dyn);
 +}
 +
 +static void parse_storage_init(sg_platf_storage_cbarg_t storage)
 +{
 +  void* stype = xbt_lib_get_or_null(storage_type_lib,
 +                                    storage->type_id,
 +                                    ROUTING_STORAGE_TYPE_LEVEL);
 +  if(!stype) xbt_die("No storage type '%s'",storage->type_id);
 +
 +  // if storage content is not specified use the content of storage_type if exist
 +  if(!strcmp(storage->content,"") && strcmp(((storage_type_t) stype)->content,"")){
 +    storage->content = ((storage_type_t) stype)->content;
-   XBT_DEBUG("SURF storage create resource\n\t\tid '%s'\n\t\ttype '%s' \n\t\tmodel '%s' \n\t\tcontent '%s'\n\t\tproperties '%p'\n",
++    storage->content_type = ((storage_type_t) stype)->content_type;
++    XBT_DEBUG("For disk '%s' content is empty, inherit the content (of type %s) from storage type '%s' ",
++        storage->id,((storage_type_t) stype)->content_type,
++        ((storage_type_t) stype)->type_id);
 +  }
 +
-                                      storage->content);
++  XBT_DEBUG("SURF storage create resource\n\t\tid '%s'\n\t\ttype '%s' "
++      "\n\t\tmodel '%s' \n\t\tcontent '%s'\n\t\tcontent_type '%s' "
++      "\n\t\tproperties '%p'\n",
 +      storage->id,
 +      ((storage_type_t) stype)->model,
 +      ((storage_type_t) stype)->type_id,
 +      storage->content,
++      storage->content_type,
 +      ((storage_type_t) stype)->properties);
 +
 +  surf_storage_model->createResource(storage->id, ((storage_type_t) stype)->model,
 +                                     ((storage_type_t) stype)->type_id,
- static xbt_dict_t parse_storage_content(char *filename, size_t *used_size)
++                                     storage->content,
++                                     storage->content_type,
++                                     storage->properties);
 +}
 +
 +static void parse_mstorage_init(sg_platf_mstorage_cbarg_t mstorage)
 +{
 +  XBT_DEBUG("parse_mstorage_init");
 +}
 +
 +static void parse_storage_type_init(sg_platf_storage_type_cbarg_t storagetype_)
 +{
 +  XBT_DEBUG("parse_storage_type_init");
 +}
 +
 +static void parse_mount_init(sg_platf_mount_cbarg_t mount)
 +{
 +  XBT_DEBUG("parse_mount_init");
 +}
 +
 +static void storage_parse_storage(sg_platf_storage_cbarg_t storage)
 +{
 +  xbt_assert(!xbt_lib_get_or_null(storage_lib, storage->id,ROUTING_STORAGE_LEVEL),
 +               "Reading a storage, processing unit \"%s\" already exists", storage->id);
 +
 +  // Verification of an existing type_id
 +#ifndef NDEBUG
 +  void* storage_type = xbt_lib_get_or_null(storage_type_lib, storage->type_id,ROUTING_STORAGE_TYPE_LEVEL);
 +#endif
 +  xbt_assert(storage_type,"Reading a storage, type id \"%s\" does not exists", storage->type_id);
 +
 +  XBT_DEBUG("ROUTING Create a storage name '%s' with type_id '%s' and content '%s'",
 +      storage->id,
 +      storage->type_id,
 +      storage->content);
 +
 +  xbt_lib_set(storage_lib,
 +      storage->id,
 +      ROUTING_STORAGE_LEVEL,
 +      (void *) xbt_strdup(storage->type_id));
 +}
 +
-   xbt_dict_t parse_content = xbt_dict_new_homogeneous(NULL);
++static xbt_dict_t parse_storage_content(char *filename, sg_storage_size_t *used_size)
 +{
 +  *used_size = 0;
 +  if ((!filename) || (strcmp(filename, "") == 0))
 +    return NULL;
 +
-   size_t size;
++  xbt_dict_t parse_content = xbt_dict_new_homogeneous(xbt_free);
 +  FILE *file = NULL;
 +
 +  file = surf_fopen(filename, "r");
 +  xbt_assert(file != NULL, "Cannot open file '%s' (path=%s)", filename,
 +              xbt_str_join(surf_path, ":"));
 +
 +  char *line = NULL;
 +  size_t len = 0;
 +  ssize_t read;
 +  char path[1024];
-     if(sscanf(line,"%s %zu",path, &size)==2) {
++  sg_storage_size_t size;
 +
 +
 +  while ((read = xbt_getline(&line, &len, file)) != -1) {
 +    if (read){
-         xbt_dict_set(parse_content,path,(void*) size,NULL);
++    if(sscanf(line,"%s %" SCNu64, path, &size) == 2) {
 +        *used_size += size;
-   stype->size = storage_type->size * 1000000000; /* storage_type->size is in Gbytes and stype->sizeis in bytes */
++        sg_storage_size_t *psize = xbt_new(sg_storage_size_t, 1);
++        *psize = size;
++        xbt_dict_set(parse_content,path,psize,NULL);
 +      } else {
 +        xbt_die("Be sure of passing a good format for content file.\n");
 +      }
 +    }
 +  }
 +  free(line);
 +  fclose(file);
 +  return parse_content;
 +}
 +
 +static void storage_parse_storage_type(sg_platf_storage_type_cbarg_t storage_type)
 +{
 +  xbt_assert(!xbt_lib_get_or_null(storage_type_lib, storage_type->id,ROUTING_STORAGE_TYPE_LEVEL),
 +               "Reading a storage type, processing unit \"%s\" already exists", storage_type->id);
 +
 +  storage_type_t stype = xbt_new0(s_storage_type_t, 1);
 +  stype->model = xbt_strdup(storage_type->model);
 +  stype->properties = storage_type->properties;
 +  stype->content = xbt_strdup(storage_type->content);
++  stype->content_type = xbt_strdup(storage_type->content_type);
 +  stype->type_id = xbt_strdup(storage_type->id);
-   XBT_DEBUG("ROUTING Create a storage type id '%s' with model '%s' content '%s'",
++  stype->size = storage_type->size;
 +
-       storage_type->content);
++  XBT_DEBUG("ROUTING Create a storage type id '%s' with model '%s', "
++      "content '%s', and content_type '%s'",
 +      stype->type_id,
 +      stype->model,
-   void* storage = xbt_lib_get_or_null(storage_lib, mount->id,ROUTING_STORAGE_LEVEL);
++      storage_type->content,
++      storage_type->content_type);
 +
 +  xbt_lib_set(storage_type_lib,
 +      stype->type_id,
 +      ROUTING_STORAGE_TYPE_LEVEL,
 +      (void *) stype);
 +}
 +static void storage_parse_mstorage(sg_platf_mstorage_cbarg_t mstorage)
 +{
 +  THROW_UNIMPLEMENTED;
 +//  mount_t mnt = xbt_new0(s_mount_t, 1);
 +//  mnt->id = xbt_strdup(mstorage->type_id);
 +//  mnt->name = xbt_strdup(mstorage->name);
 +//
 +//  if(!mount_list){
 +//    XBT_DEBUG("Creata a Mount list for %s",A_surfxml_host_id);
 +//    mount_list = xbt_dynar_new(sizeof(char *), NULL);
 +//  }
 +//  xbt_dynar_push(mount_list,(void *) mnt);
 +//  free(mnt->id);
 +//  free(mnt->name);
 +//  xbt_free(mnt);
 +//  XBT_DEBUG("ROUTING Mount a storage name '%s' with type_id '%s'",mstorage->name, mstorage->id);
 +}
 +
 +static void mount_free(void *p)
 +{
 +  mount_t mnt = (mount_t) p;
 +  xbt_free(mnt->name);
 +}
 +
 +static void storage_parse_mount(sg_platf_mount_cbarg_t mount)
 +{
 +  // Verification of an existing storage
 +#ifndef NDEBUG
-   xbt_assert(storage,"Disk id \"%s\" does not exists", mount->id);
++  void* storage = xbt_lib_get_or_null(storage_lib, mount->storageId, ROUTING_STORAGE_LEVEL);
 +#endif
-   XBT_DEBUG("ROUTING Mount '%s' on '%s'",mount->id, mount->name);
++  xbt_assert(storage,"Disk id \"%s\" does not exists", mount->storageId);
 +
-   mnt.id = surf_storage_resource_priv(surf_storage_resource_by_name(mount->id));
++  XBT_DEBUG("ROUTING Mount '%s' on '%s'",mount->storageId, mount->name);
 +
 +  s_mount_t mnt;
- StoragePtr StorageModel::createResource(const char* id, const char* model, const char* type_id, const char* content_name)
++  mnt.storage = surf_storage_resource_priv(surf_storage_resource_by_name(mount->storageId));
 +  mnt.name = xbt_strdup(mount->name);
 +
 +  if(!mount_list){
 +    //FIXME: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 storage_define_callbacks()
 +{
 +  sg_platf_storage_add_cb(parse_storage_init);
 +  sg_platf_storage_type_add_cb(parse_storage_type_init);
 +  sg_platf_mstorage_add_cb(parse_mstorage_init);
 +  sg_platf_mount_add_cb(parse_mount_init);
 +}
 +
 +void storage_register_callbacks() {
 +
 +  ROUTING_STORAGE_LEVEL = xbt_lib_add_level(storage_lib,xbt_free);
 +  ROUTING_STORAGE_HOST_LEVEL = xbt_lib_add_level(storage_lib, routing_storage_host_free);
 +  ROUTING_STORAGE_TYPE_LEVEL = xbt_lib_add_level(storage_type_lib, routing_storage_type_free);
 +  SURF_STORAGE_LEVEL = xbt_lib_add_level(storage_lib, surf_storage_resource_free);
 +
 +  sg_platf_storage_add_cb(storage_parse_storage);
 +  sg_platf_mstorage_add_cb(storage_parse_mstorage);
 +  sg_platf_storage_type_add_cb(storage_parse_storage_type);
 +  sg_platf_mount_add_cb(storage_parse_mount);
 +}
 +
 +/*********
 + * Model *
 + *********/
 +
 +void surf_storage_model_init_default(void)
 +{
 +  surf_storage_model = new StorageModel();
 +  storage_define_callbacks();
 +  xbt_dynar_push(model_list, &surf_storage_model);
 +}
 +
 +StorageModel::StorageModel() : Model("Storage") {
 +  StorageActionLmm action;
 +
 +  XBT_DEBUG("surf_storage_model_init_internal");
 +
 +  storage_running_action_set_that_does_not_need_being_checked =
 +      xbt_swag_new(xbt_swag_offset(action, p_stateHookup));
 +
 +  if (!p_maxminSystem) {
 +    p_maxminSystem = lmm_system_new(storage_selective_update);
 +  }
 +}
 +
 +
 +StorageModel::~StorageModel(){
 +  lmm_system_free(p_maxminSystem);
 +
 +  surf_storage_model = NULL;
 +
 +  xbt_dynar_free(&storage_list);
 +
 +  xbt_swag_free(storage_running_action_set_that_does_not_need_being_checked);
 +  storage_running_action_set_that_does_not_need_being_checked = NULL;
 +}
 +
-   double Bread  = atof((char*)xbt_dict_get(storage_type->properties, "Bread"));
-   double Bwrite = atof((char*)xbt_dict_get(storage_type->properties, "Bwrite"));
-   double Bconnection   = atof((char*)xbt_dict_get(storage_type->properties, "Bconnection"));
++StoragePtr StorageModel::createResource(const char* id, const char* model, const char* type_id,
++              const char* content_name, const char* content_type, xbt_dict_t properties)
 +{
 +
 +  xbt_assert(!surf_storage_resource_priv(surf_storage_resource_by_name(id)),
 +              "Storage '%s' declared several times in the platform file",
 +              id);
 +
 +  storage_type_t storage_type = (storage_type_t) xbt_lib_get_or_null(storage_type_lib, type_id,ROUTING_STORAGE_TYPE_LEVEL);
 +
-   StoragePtr storage = new StorageLmm(this, NULL, NULL, p_maxminSystem,
-                 Bread, Bwrite, Bconnection, (char *)content_name, storage_type->size);
++  double Bread  = surf_parse_get_bandwidth((char*)xbt_dict_get(storage_type->properties, "Bread"));
++  double Bwrite = surf_parse_get_bandwidth((char*)xbt_dict_get(storage_type->properties, "Bwrite"));
++  double Bconnection   = surf_parse_get_bandwidth((char*)xbt_dict_get(storage_type->properties, "Bconnection"));
 +
-   xbt_lib_set(storage_lib, id, SURF_STORAGE_LEVEL, storage);
++  StoragePtr storage = new StorageLmm(this, id, properties, p_maxminSystem,
++                Bread, Bwrite, Bconnection,
++                type_id, (char *)content_name, xbt_strdup(content_type), storage_type->size);
 +
-   if(!storage_list) storage_list=xbt_dynar_new(sizeof(char *),NULL);
++  xbt_lib_set(storage_lib, id, SURF_STORAGE_LEVEL, static_cast<ResourcePtr>(storage));
 +
 +  XBT_DEBUG("SURF storage create resource\n\t\tid '%s'\n\t\ttype '%s' \n\t\tmodel '%s' \n\t\tproperties '%p'\n\t\tBread '%f'\n",
 +      id,
 +      model,
 +      type_id,
 +      storage_type->properties,
 +      Bread);
 +
-   // Update the disk usage
-   // Update the file size
-   // For each action of type write
++  if(!storage_list)
++      storage_list = xbt_dynar_new(sizeof(char *),NULL);
 +  xbt_dynar_push(storage_list, &storage);
 +
 +  return storage;
 +}
 +
 +double StorageModel::shareResources(double now)
 +{
 +  XBT_DEBUG("storage_share_resources %f", now);
 +  unsigned int i, j;
 +  StoragePtr storage;
 +  StorageActionLmmPtr write_action;
 +
 +  double min_completion = shareResourcesMaxMin(p_runningActionSet,
 +      p_maxminSystem, lmm_solve);
 +
 +  double rate;
 +  // Foreach disk
 +  xbt_dynar_foreach(storage_list,i,storage)
 +  {
 +    rate = 0;
 +    // Foreach write action on disk
 +    xbt_dynar_foreach(storage->p_writeActions, j, write_action)
 +    {
 +      rate += lmm_variable_getvalue(write_action->p_variable);
 +    }
 +    if(rate > 0)
 +      min_completion = MIN(min_completion, (storage->m_size-storage->m_usedSize)/rate);
 +  }
 +
 +  return min_completion;
 +}
 +
 +void StorageModel::updateActionsState(double now, double delta)
 +{
 +  void *_action, *_next_action;
 +  StorageActionLmmPtr action = NULL;
 +
-        * (note that the next sizes are of type size_t). */
 +  xbt_swag_foreach_safe(_action, _next_action, p_runningActionSet) {
 +      action = dynamic_cast<StorageActionLmmPtr>(static_cast<ActionPtr>(_action));
 +    if(action->m_type == WRITE)
 +    {
++      // Update the disk usage
++     // Update the file size
++     // For each action of type write
 +      double rate = lmm_variable_getvalue(action->p_variable);
 +      /* Hack to avoid rounding differences between x86 and x86_64
-     }
-   }
++       * (note that the next sizes are of type sg_storage_size_t). */
 +      long incr = delta * rate + MAXMIN_PRECISION;
 +      action->p_storage->m_usedSize += incr; // disk usage
 +      action->p_file->size += incr; // file size
-   xbt_swag_foreach_safe(_action, _next_action, p_runningActionSet) {
-       action = dynamic_cast<StorageActionLmmPtr>(static_cast<ActionPtr>(_action));
 +
-   xbt_dict_t parse_content = xbt_dict_new_homogeneous(NULL);
++      sg_storage_size_t *psize = xbt_new(sg_storage_size_t,1);
++      *psize = action->p_file->size;
++
++      xbt_dict_t content_dict = action->p_storage->p_content;
++      xbt_dict_set(content_dict, action->p_file->name, psize, NULL);
++    }
 +
 +    double_update(&action->m_remains,
 +                  lmm_variable_getvalue(action->p_variable) * delta);
 +
 +    if (action->m_maxDuration != NO_MAX_DURATION)
 +      double_update(&action->m_maxDuration, delta);
 +
 +    if(action->m_remains > 0 &&
 +        lmm_get_variable_weight(action->p_variable) > 0 &&
 +        action->p_storage->m_usedSize == action->p_storage->m_size)
 +    {
 +      action->m_finish = surf_get_clock();
 +      action->setState(SURF_ACTION_FAILED);
 +    } else if ((action->m_remains <= 0) &&
 +        (lmm_get_variable_weight(action->p_variable) > 0))
 +    {
 +      action->m_finish = surf_get_clock();
 +      action->setState(SURF_ACTION_DONE);
 +    } else if ((action->m_maxDuration != NO_MAX_DURATION) &&
 +               (action->m_maxDuration <= 0))
 +    {
 +      action->m_finish = surf_get_clock();
 +      action->setState(SURF_ACTION_DONE);
 +    }
 +  }
 +
 +  return;
 +}
 +
 +xbt_dict_t Storage::parseContent(char *filename)
 +{
 +  m_usedSize = 0;
 +  if ((!filename) || (strcmp(filename, "") == 0))
 +    return NULL;
 +
-   size_t size;
++  xbt_dict_t parse_content = xbt_dict_new_homogeneous(xbt_free);
 +  FILE *file = NULL;
 +
 +  file = surf_fopen(filename, "r");
 +  xbt_assert(file != NULL, "Cannot open file '%s' (path=%s)", filename,
 +              xbt_str_join(surf_path, ":"));
 +
 +  char *line = NULL;
 +  size_t len = 0;
 +  ssize_t read;
 +  char path[1024];
-     if(sscanf(line,"%s %zu",path, &size)==2) {
++  sg_storage_size_t size;
 +
 +
 +  while ((read = xbt_getline(&line, &len, file)) != -1) {
 +    if (read){
-         xbt_dict_set(parse_content,path,(void*) size,NULL);
++    if(sscanf(line,"%s %" SCNu64, path, &size) == 2) {
 +        m_usedSize += size;
-            char *content_name, size_t size)
++        sg_storage_size_t *psize = xbt_new(sg_storage_size_t, 1);
++        *psize = size;
++        xbt_dict_set(parse_content,path,psize,NULL);
 +      } else {
 +        xbt_die("Be sure of passing a good format for content file.\n");
 +      }
 +    }
 +  }
 +  free(line);
 +  fclose(file);
 +  return parse_content;
 +}
 +
 +/************
 + * Resource *
 + ************/
 +
 +Storage::Storage(StorageModelPtr model, const char* name, xbt_dict_t properties)
 +:  Resource(model, name, properties)
 +{
 +  p_writeActions = xbt_dynar_new(sizeof(char *),NULL);
 +}
 +
 +StorageLmm::StorageLmm(StorageModelPtr model, const char* name, xbt_dict_t properties,
 +           lmm_system_t maxminSystem, double bread, double bwrite, double bconnection,
-   xbt_dict_t ls_dict = xbt_dict_new();
++           const char* type_id, char *content_name, char *content_type, size_t size)
 + :  Resource(model, name, properties), ResourceLmm(), Storage(model, name, properties) {
 +  XBT_DEBUG("Create resource with Bconnection '%f' Bread '%f' Bwrite '%f' and Size '%lu'", bconnection, bread, bwrite, ((unsigned long)size));
 +
 +  p_stateCurrent = SURF_RESOURCE_ON;
 +  m_usedSize = 0;
 +  m_size = 0;
 +
 +  p_content = parseContent(content_name);
++  p_contentType = content_type;
 +  p_constraint = lmm_constraint_new(maxminSystem, this, bconnection);
 +  p_constraintRead  = lmm_constraint_new(maxminSystem, this, bread);
 +  p_constraintWrite = lmm_constraint_new(maxminSystem, this, bwrite);
 +  m_size = size;
++  p_typeId = xbt_strdup(type_id);
 +}
 +
 +bool Storage::isUsed()
 +{
 +  THROW_UNIMPLEMENTED;
 +  return false;
 +}
 +
 +void Storage::updateState(tmgr_trace_event_t event_type, double value, double date)
 +{
 +  THROW_UNIMPLEMENTED;
 +}
 +
 +StorageActionPtr StorageLmm::ls(const char* path)
 +{
 +  StorageActionLmmPtr action = new StorageActionLmm(p_model, 0, p_stateCurrent != SURF_RESOURCE_ON, this, LS);
 +
 +  action->p_lsDict = NULL;
-   size_t size = 0;
++  xbt_dict_t ls_dict = xbt_dict_new_homogeneous(xbt_free);
 +
 +  char* key;
-         xbt_dict_set(ls_dict,file,&size,NULL);
++  sg_storage_size_t size = 0;
 +  xbt_dict_cursor_t cursor = NULL;
 +
 +  xbt_dynar_t dyn = NULL;
 +  char* file = NULL;
 +
 +  // for each file in the storage content
 +  xbt_dict_foreach(p_content,cursor,key,size){
 +    // Search if file start with the prefix 'path'
 +    if(xbt_str_start_with(key,path)){
 +      file = &key[strlen(path)];
 +
 +      // Split file with '/'
 +      dyn = xbt_str_split(file,"/");
 +      file = xbt_dynar_get_as(dyn,0,char*);
 +
 +      // file
 +      if(xbt_dynar_length(dyn) == 1){
-   size_t size = (size_t) xbt_dict_get_or_null(p_content, path);
++        sg_storage_size_t *psize = xbt_new(sg_storage_size_t, 1);
++        *psize=size;
++        xbt_dict_set(ls_dict, file, psize, NULL);
 +      }
 +      // Directory
 +      else
 +      {
 +        // if directory does not exist yet in the dictionary
 +        if(!xbt_dict_get_or_null(ls_dict,file))
 +          xbt_dict_set(ls_dict,file,NULL,NULL);
 +      }
 +      xbt_dynar_free(&dyn);
 +    }
 +  }
 +
 +  action->p_lsDict = ls_dict;
 +  return action;
 +}
 +
 +StorageActionPtr StorageLmm::open(const char* mount, const char* path)
 +{
 +  XBT_DEBUG("\tOpen file '%s'",path);
-   if(!size){
-     xbt_dict_set(p_content, path, &size, NULL);
++  sg_storage_size_t size, *psize;
++  psize = (sg_storage_size_t*) xbt_dict_get_or_null(p_content, path);
 +  // if file does not exist create an empty file
-   file->storage = xbt_strdup(mount);
++  if(psize)
++    size = *psize;
++  else {
++      psize = xbt_new(sg_storage_size_t,1);
++    size = 0;
++    *psize = size;
++    xbt_dict_set(p_content, path, psize, NULL);
 +    XBT_DEBUG("File '%s' was not found, file created.",path);
 +  }
 +  surf_file_t file = xbt_new0(s_surf_file_t,1);
 +  file->name = xbt_strdup(path);
 +  file->size = size;
-   XBT_DEBUG("\tClose file '%s' size '%zu'", filename, fd->size);
++  file->mount = xbt_strdup(mount);
 +
 +  StorageActionLmmPtr action = new StorageActionLmm(p_model, 0, p_stateCurrent != SURF_RESOURCE_ON, this, OPEN);
 +  action->p_file = file;
 +  return action;
 +}
 +
 +StorageActionPtr StorageLmm::close(surf_file_t fd)
 +{
 +  char *filename = fd->name;
-   free(fd->storage);
++  XBT_DEBUG("\tClose file '%s' size '%" PRIu64 "'", filename, fd->size);
 +  // unref write actions from storage
 +  StorageActionLmmPtr write_action;
 +  unsigned int i;
 +  xbt_dynar_foreach(p_writeActions, i, write_action) {
 +    if ((write_action->p_file) == fd) {
 +      xbt_dynar_cursor_rm(p_writeActions, &i);
 +      write_action->unref();
 +    }
 +  }
 +  free(fd->name);
- StorageActionPtr StorageLmm::read(void* ptr, size_t size, surf_file_t fd)
++  free(fd->mount);
 +  xbt_free(fd);
 +  StorageActionLmmPtr action = new StorageActionLmm(p_model, 0, p_stateCurrent != SURF_RESOURCE_ON, this, CLOSE);
 +  return action;
 +}
 +
- StorageActionPtr StorageLmm::write(const void* ptr, size_t size, surf_file_t fd)
++StorageActionPtr StorageLmm::read(surf_file_t fd, sg_storage_size_t size)
 +{
 +  if(size > fd->size)
 +    size = fd->size;
 +  StorageActionLmmPtr action = new StorageActionLmm(p_model, size, p_stateCurrent != SURF_RESOURCE_ON, this, READ);
 +  return action;
 +}
 +
-   XBT_DEBUG("\tWrite file '%s' size '%zu/%zu'",filename,size,fd->size);
++StorageActionPtr StorageLmm::write(surf_file_t fd, sg_storage_size_t size)
 +{
 +  char *filename = fd->name;
-   XBT_IN("(%s,%zu", storage->m_name, cost);
++  XBT_DEBUG("\tWrite file '%s' size '%" PRIu64 "/%" PRIu64 "'",filename,size,fd->size);
 +
 +  StorageActionLmmPtr action = new StorageActionLmm(p_model, size, p_stateCurrent != SURF_RESOURCE_ON, this, WRITE);
 +  action->p_file = fd;
 +
 +  // If the storage is full
 +  if(m_usedSize==m_size) {
 +    action->setState(SURF_ACTION_FAILED);
 +  }
 +  return action;
 +}
 +
++xbt_dict_t StorageLmm::getContent()
++{
++  /* For the moment this action has no cost, but in the future we could take in account access latency of the disk */
++  /*surf_action_t action = storage_action_execute(storage,0, LS);*/
++
++  xbt_dict_t content_dict = xbt_dict_new_homogeneous(NULL);
++  xbt_dict_cursor_t cursor = NULL;
++  char *file;
++  sg_storage_size_t *psize;
++
++  xbt_dict_foreach(p_content, cursor, file, psize){
++    xbt_dict_set(content_dict,file,psize,NULL);
++  }
++  return content_dict;
++}
++
++sg_storage_size_t StorageLmm::getSize(){
++  return m_size;
++}
++
 +/**********
 + * Action *
 + **********/
 +
 +StorageActionLmm::StorageActionLmm(ModelPtr model, double cost, bool failed, StorageLmmPtr storage, e_surf_action_storage_type_t type)
 +  : Action(model, cost, failed), ActionLmm(model, cost, failed), StorageAction(model, cost, failed, storage, type) {
++  XBT_IN("(%s,%" PRIu64, storage->m_name, cost);
 +  p_variable = lmm_variable_new(p_model->p_maxminSystem, this, 1.0, -1.0 , 3);
 +
 +  // Must be less than the max bandwidth for all actions
 +  lmm_expand(p_model->p_maxminSystem, storage->p_constraint, p_variable, 1.0);
 +  switch(type) {
 +  case OPEN:
 +  case CLOSE:
 +  case STAT:
 +  case LS:
 +    break;
 +  case READ:
 +    lmm_expand(p_model->p_maxminSystem, storage->p_constraintRead,
 +               p_variable, 1.0);
 +    break;
 +  case WRITE:
 +    lmm_expand(p_model->p_maxminSystem, storage->p_constraintWrite,
 +               p_variable, 1.0);
 +    xbt_dynar_push(storage->p_writeActions, static_cast<ActionPtr>(this));
 +    break;
 +  }
 +  XBT_OUT();
 +}
 +
 +int StorageActionLmm::unref()
 +{
 +  m_refcount--;
 +  if (!m_refcount) {
 +    xbt_swag_remove(static_cast<ActionPtr>(this), p_stateSet);
 +    if (p_variable)
 +      lmm_variable_free(p_model->p_maxminSystem, p_variable);
 +#ifdef HAVE_TRACING
 +    xbt_free(p_category);
 +#endif
 +    delete this;
 +    return 1;
 +  }
 +  return 0;
 +}
 +
 +void StorageActionLmm::cancel()
 +{
 +  setState(SURF_ACTION_FAILED);
 +  return;
 +}
 +
 +void StorageActionLmm::suspend()
 +{
 +  XBT_IN("(%p)", this);
 +  if (m_suspended != 2) {
 +    lmm_update_variable_weight(p_model->p_maxminSystem,
 +                               p_variable,
 +                               0.0);
 +    m_suspended = 1;
 +  }
 +  XBT_OUT();
 +}
 +
 +void StorageActionLmm::resume()
 +{
 +  THROW_UNIMPLEMENTED;
 +}
 +
 +bool StorageActionLmm::isSuspended()
 +{
 +  return m_suspended == 1;
 +}
 +
 +void StorageActionLmm::setMaxDuration(double duration)
 +{
 +  THROW_UNIMPLEMENTED;
 +}
 +
 +void StorageActionLmm::setPriority(double priority)
 +{
 +  THROW_UNIMPLEMENTED;
 +}
 +
diff --combined src/surf/storage.hpp
index 94ac7fd,0000000..cceebf5
mode 100644,000000..100644
--- /dev/null
@@@ -1,143 -1,0 +1,150 @@@
-   StoragePtr createResource(const char* id, const char* model, const char* type_id, const char* content_name);
 +#include "surf.hpp"
 +
 +#ifndef STORAGE_HPP_
 +#define STORAGE_HPP_
 +
 +/***********
 + * Classes *
 + ***********/
 +
 +class StorageModel;
 +typedef StorageModel *StorageModelPtr;
 +
 +class Storage;
 +typedef Storage *StoragePtr;
 +
 +class StorageLmm;
 +typedef StorageLmm *StorageLmmPtr;
 +
 +class StorageAction;
 +typedef StorageAction *StorageActionPtr;
 +
 +class StorageActionLmm;
 +typedef StorageActionLmm *StorageActionLmmPtr;
 +
 +
 +/*********
 + * Model *
 + *********/
 +class StorageModel : public Model {
 +public:
 +  StorageModel();
 +  ~StorageModel();
-   xbt_dict_t p_content; /* char * -> s_surf_file_t */
++  StoragePtr createResource(const char* id, const char* model, const char* type_id,
++                 const char* content_name, const char* content_type, xbt_dict_t properties);
 +  double shareResources(double now);
 +  void updateActionsState(double now, double delta);
 +
 +};
 +
 +/************
 + * Resource *
 + ************/
 +
 +class Storage : virtual public Resource {
 +public:
 +  Storage(StorageModelPtr model, const char* name, xbt_dict_t properties);
 +
 +  bool isUsed();
 +  void updateState(tmgr_trace_event_t event_type, double value, double date);
 +
-   //virtual size_t getSize(surf_file_t fd);
-   virtual StorageActionPtr read(void* ptr, size_t size, surf_file_t fd)=0;//FIXME:why we have a useless param ptr ??
-   virtual StorageActionPtr write(const void* ptr, size_t size, surf_file_t fd)=0;//FIXME:why we have a useless param ptr ??
++  xbt_dict_t p_content;
++  char* p_contentType;
++  sg_storage_size_t m_size;
++  sg_storage_size_t m_usedSize;
++  char * p_typeId;
 +
 +  virtual StorageActionPtr open(const char* mount, const char* path)=0;
 +  virtual StorageActionPtr close(surf_file_t fd)=0;
 +  //virtual StorageActionPtr unlink(surf_file_t fd)=0;
 +  virtual StorageActionPtr ls(const char *path)=0;
-   size_t m_size;
-   size_t m_usedSize;
++  virtual StorageActionPtr read(surf_file_t fd, sg_storage_size_t size)=0;
++  virtual StorageActionPtr write(surf_file_t fd, sg_storage_size_t size)=0;
++  virtual xbt_dict_t getContent()=0;
++  virtual sg_storage_size_t getSize()=0;
++
 +  xbt_dict_t parseContent(char *filename);
 +
-                    char *content_name, size_t size);
 +  xbt_dynar_t p_writeActions;
 +};
 +
 +class StorageLmm : public ResourceLmm, public Storage {
 +public:
 +  StorageLmm(StorageModelPtr model, const char* name, xbt_dict_t properties,
 +                   lmm_system_t maxminSystem, double bread, double bwrite, double bconnection,
-   //size_t getSize(surf_file_t fd);
-   StorageActionPtr read(void* ptr, size_t size, surf_file_t fd);//FIXME:why we have a useless param ptr ??
-   StorageActionPtr write(const void* ptr, size_t size, surf_file_t fd);//FIXME:why we have a useless param ptr ??
++                   const char* type_id, char *content_name, char *content_type, size_t size);
 +
 +  StorageActionPtr open(const char* mount, const char* path);
 +  StorageActionPtr close(surf_file_t fd);
 +  //StorageActionPtr unlink(surf_file_t fd);
 +  StorageActionPtr ls(const char *path);
-   size_t size;
++  xbt_dict_t getContent();
++  sg_storage_size_t getSize();
++  StorageActionPtr read(surf_file_t fd, sg_storage_size_t size);//FIXME:why we have a useless param ptr ??
++  StorageActionPtr write(surf_file_t fd, sg_storage_size_t size);//FIXME:why we have a useless param ptr ??
 +
 +  lmm_constraint_t p_constraintWrite;    /* Constraint for maximum write bandwidth*/
 +  lmm_constraint_t p_constraintRead;     /* Constraint for maximum write bandwidth*/
 +};
 +
 +/**********
 + * Action *
 + **********/
 +
 +typedef enum {
 +  READ=0, WRITE, STAT, OPEN, CLOSE, LS
 +} e_surf_action_storage_type_t;
 +
 +
 +class StorageAction : virtual public Action {
 +public:
 +  StorageAction(){};
 +  StorageAction(ModelPtr model, double cost, bool failed, StoragePtr storage, e_surf_action_storage_type_t type)
 +   : p_storage(storage), m_type(type) {};
 +
 +
 +
 +  e_surf_action_storage_type_t m_type;
 +  StoragePtr p_storage;
 +  surf_file_t p_file;
 +  xbt_dict_t p_lsDict;
 +};
 +
 +class StorageActionLmm : public ActionLmm, public StorageAction {
 +public:
 +  StorageActionLmm(){};
 +  StorageActionLmm(ModelPtr model, double cost, bool failed, StorageLmmPtr storage, e_surf_action_storage_type_t type);
 +  void suspend();
 +  int unref();
 +  void cancel();
 +  //FIXME:??void recycle();
 +  void resume();
 +  bool isSuspended();
 +  void setMaxDuration(double duration);
 +  void setPriority(double priority);
 +
 +};
 +
 +
 +typedef struct s_storage_type {
 +  char *model;
 +  char *content;
++  char *content_type;
 +  char *type_id;
 +  xbt_dict_t properties;
-   void *id;
++  sg_storage_size_t size;
 +} s_storage_type_t, *storage_type_t;
 +
 +typedef struct s_mount {
-   char *storage;
-   size_t size;
++  void *storage;
 +  char *name;
 +} s_mount_t, *mount_t;
 +
 +typedef struct surf_file {
 +  char *name;
++  char *mount;
++  sg_storage_size_t size;
 +} s_surf_file_t;
 +
 +
 +#endif /* STORAGE_HPP_ */
@@@ -1,4 -1,4 +1,4 @@@
- /* Copyright (c) 2009, 2013. The SimGrid Team.
+ /* Copyright (c) 2009, 2012-2013. The SimGrid Team.
   * All rights reserved.                                                     */
  
  /* This program is free software; you can redistribute it and/or modify it
  typedef struct s_storage_type {
    char *model;
    char *content;
+   char *content_type;
    char *type_id;
    xbt_dict_t properties;
-   size_t size;
+   sg_storage_size_t size;
  } s_storage_type_t, *storage_type_t;
  
  typedef struct s_mount {
-   void *id;
+   void *storage;
    char *name;
  } s_mount_t, *mount_t;
  
  typedef struct surf_file {
    char *name;
-   char *storage;
-   size_t size;
+   char *mount;
+   sg_storage_size_t size;
  } s_surf_file_t;
  
++<<<<<<< HEAD
 +typedef struct storage {
 +  //FIXME:s_surf_resource_t generic_resource;   /*< Structure with generic data. Needed at begin to interact with SURF */
++||||||| merged common ancestors
++typedef struct storage {
++  s_surf_resource_t generic_resource;   /*< Structure with generic data. Needed at begin to interact with SURF */
++=======
+ typedef struct surf_storage {
+   s_surf_resource_t generic_resource;   /*< Structure with generic data. Needed at begin to interact with SURF */
++>>>>>>> 045db1657e870c721be490b411868f4181a12ced
    e_surf_resource_state_t state_current;        /*< STORAGE current state (ON or OFF) */
    lmm_constraint_t constraint;          /* Constraint for maximum bandwidth from connection */
    lmm_constraint_t constraint_write;    /* Constraint for maximum write bandwidth*/
    lmm_constraint_t constraint_read;     /* Constraint for maximum write bandwidth*/
-   xbt_dict_t content; /* char * -> s_surf_file_t */
-   size_t size;
-   size_t used_size;
+   xbt_dict_t content;
+   char* content_type;
+   sg_storage_size_t size;
+   sg_storage_size_t used_size;
+   char *type_id;
    xbt_dynar_t write_actions;
+   xbt_dict_t properties;
  } s_storage_t, *storage_t;
  
  typedef enum {
@@@ -43,7 -47,7 +55,7 @@@
  } e_surf_action_storage_type_t;
  
  typedef struct surf_action_storage {
 -  s_surf_action_lmm_t generic_lmm_action;
 +  //FIXME:s_surf_action_lmm_t generic_lmm_action;
    e_surf_action_storage_type_t type;
    void *storage;
  } s_surf_action_storage_t, *surf_action_storage_t;
diff --combined src/surf/surf.cpp
index 41545d8,0000000..010de57
mode 100644,000000..100644
--- /dev/null
@@@ -1,1070 -1,0 +1,1053 @@@
- void surf_watched_hosts(void)
 +#include "surf_private.h"
 +#include "surf.hpp"
 +#include "network.hpp"
 +#include "cpu.hpp"
 +#include "workstation.hpp"
 +#include "simix/smx_host_private.h"
 +#include "surf_routing.hpp"
 +#include "simgrid/sg_config.h"
 +#include "mc/mc.h"
 +
 +extern "C" {
 +XBT_LOG_NEW_CATEGORY(surf, "All SURF categories");
 +XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_kernel, surf,
 +                                "Logging specific to SURF (kernel)");
 +}
 +
 +/*********
 + * Utils *
 + *********/
 +
 +/* This function is a pimple that we ought to fix. But it won't be easy.
 + *
 + * The surf_solve() function does properly return the set of actions that changed.
 + * Instead, each model change a global data, and then the caller of surf_solve must
 + * pick into these sets of action_failed and action_done.
 + *
 + * This was not clean but ok as long as we didn't had to restart the processes when the resource comes back up.
 + * We worked by putting sentinel actions on every resources we are interested in,
 + * so that surf informs us if/when the corresponding resource fails.
 + *
 + * But this does not work to get Simix informed of when a resource comes back up, and this is where this pimple comes.
 + * We have a set of resources that are currently down and for which simix needs to know when it comes back up.
 + * And the current function is called *at every simulation step* to sweep over that set, searching for a resource
 + * that was turned back up in the meanwhile. This is UGLY and slow.
 + *
 + * The proper solution would be to not rely on globals for the action_failed and action_done swags.
 + * They must be passed as parameter by the caller (the handling of these actions in simix may let you
 + * think that these two sets can be merged, but their handling in SimDag induce the contrary unless this
 + * simdag code can check by itself whether the action is done of failed -- seems very doable, but yet more
 + * cleanup to do).
 + *
 + * Once surf_solve() is passed the set of actions that changed, you want to add a new set of resources back up
 + * as parameter to this function. You also want to add a boolean field "restart_watched" to each resource, and
 + * make sure that whenever a resource with this field enabled comes back up, it's added to that set so that Simix
 + * sees it and react accordingly. This would kill that need for surf to call simix.
 + *
 + */
 +
 +static void remove_watched_host(void *key)
 +{
 +  xbt_dict_remove(watched_hosts_lib, *(char**)key);
 +}
 +
- }
++/*void surf_watched_hosts(void)
 +{
 +  char *key;
 +  void *host;
 +  xbt_dict_cursor_t cursor;
 +  xbt_dynar_t hosts = xbt_dynar_new(sizeof(char*), NULL);
 +
 +  XBT_DEBUG("Check for host SURF_RESOURCE_ON on watched_hosts_lib");
 +  xbt_dict_foreach(watched_hosts_lib, cursor, key, host)
 +  {
 +    if(SIMIX_host_get_state((smx_host_t)host) == SURF_RESOURCE_ON){
 +      XBT_INFO("Restart processes on host: %s", SIMIX_host_get_name((smx_host_t)host));
 +      SIMIX_host_autorestart((smx_host_t)host);
 +      xbt_dynar_push_as(hosts, char*, key);
 +    }
 +    else
 +      XBT_DEBUG("See SURF_RESOURCE_OFF on host: %s",key);
 +  }
 +  xbt_dynar_map(hosts, remove_watched_host);
 +  xbt_dynar_free(&hosts);
- /*TODO: keepit void surf_watched_hosts(void)
- {
-   char *key;
-   void *_host;
-   smx_host_t host;
-   xbt_dict_cursor_t cursor;
-   xbt_dynar_t hosts = xbt_dynar_new(sizeof(char*), NULL);
-   XBT_DEBUG("Check for host SURF_RESOURCE_ON on watched_hosts_lib");
-   xbt_dict_foreach(watched_hosts_lib,cursor,key,_host)
-   {
-     host = (smx_host_t) host;
-     if(SIMIX_host_get_state(host) == SURF_RESOURCE_ON){
-       XBT_INFO("Restart processes on host: %s",SIMIX_host_get_name(host));
-       SIMIX_host_autorestart(host);
-       xbt_dynar_push_as(hosts, char*, key);
-     }
-     else
-       XBT_DEBUG("See SURF_RESOURCE_OFF on host: %s",key);
-   }
-   xbt_dynar_map(hosts, remove_watched_host);
-   xbt_dynar_free(&hosts);
- }*/
++}*/
 +
 +
 +xbt_dynar_t model_list = NULL;
 +tmgr_history_t history = NULL;
 +lmm_system_t maxmin_system = NULL;
 +xbt_dynar_t surf_path = NULL;
++xbt_dynar_t host_that_restart = NULL;
++xbt_dict_t watched_hosts_lib;
 +
 +/* Don't forget to update the option description in smx_config when you change this */
 +s_surf_model_description_t surf_network_model_description[] = {
 +  {"LV08",
 +   "Realistic network analytic model (slow-start modeled by multiplying latency by 10.4, bandwidth by .92; bottleneck sharing uses a payload of S=8775 for evaluating RTT). ",
 +   surf_network_model_init_LegrandVelho},
 +  {"Constant",
 +   "Simplistic network model where all communication take a constant time (one second). This model provides the lowest realism, but is (marginally) faster.",
 +   surf_network_model_init_Constant},
 +  {"SMPI",
 +   "Realistic network model specifically tailored for HPC settings (accurate modeling of slow start with correction factors on three intervals: < 1KiB, < 64 KiB, >= 64 KiB)",
 +   surf_network_model_init_SMPI},
 +  {"CM02",
 +   "Legacy network analytic model (Very similar to LV08, but without corrective factors. The timings of small messages are thus poorly modeled).",
 +   surf_network_model_init_CM02},
 +#ifdef HAVE_GTNETS
 +  {"GTNets",
 +   "Network pseudo-model using the GTNets simulator instead of an analytic model",
 +   surf_network_model_init_GTNETS},
 +#endif
 +#ifdef HAVE_NS3
 +  {"NS3",
 +   "Network pseudo-model using the NS3 tcp model instead of an analytic model",
 +  surf_network_model_init_NS3},
 +#endif
 +  {"Reno",
 +   "Model from Steven H. Low using lagrange_solve instead of lmm_solve (experts only; check the code for more info).",
 +   surf_network_model_init_Reno},
 +  {"Reno2",
 +   "Model from Steven H. Low using lagrange_solve instead of lmm_solve (experts only; check the code for more info).",
 +   surf_network_model_init_Reno2},
 +  {"Vegas",
 +   "Model from Steven H. Low using lagrange_solve instead of lmm_solve (experts only; check the code for more info).",
 +   surf_network_model_init_Vegas},
 +  {NULL, NULL, NULL}      /* this array must be NULL terminated */
 +};
 +
 +s_surf_model_description_t surf_cpu_model_description[] = {
 +  {"Cas01",
 +   "Simplistic CPU model (time=size/power).",
 +   surf_cpu_model_init_Cas01},
 +  {NULL, NULL,  NULL}      /* this array must be NULL terminated */
 +};
 +
 +s_surf_model_description_t surf_workstation_model_description[] = {
 +  {"default",
 +   "Default workstation model. Currently, CPU:Cas01 and network:LV08 (with cross traffic enabled)",
 +   surf_workstation_model_init_current_default},
 +  {"compound",
 +   "Workstation model that is automatically chosen if you change the network and CPU models",
 +   surf_workstation_model_init_compound},
 +  {"ptask_L07", "Workstation model somehow similar to Cas01+CM02 but allowing parallel tasks",
 +   surf_workstation_model_init_ptask_L07},
 +  {NULL, NULL, NULL}      /* this array must be NULL terminated */
 +};
 +
 +s_surf_model_description_t surf_optimization_mode_description[] = {
 +  {"Lazy",
 +   "Lazy action management (partial invalidation in lmm + heap in action remaining).",
 +   NULL},
 +  {"TI",
 +   "Trace integration. Highly optimized mode when using availability traces (only available for the Cas01 CPU model for now).",
 +    NULL},
 +  {"Full",
 +   "Full update of remaining and variables. Slow but may be useful when debugging.",
 +   NULL},
 +  {NULL, NULL, NULL}      /* this array must be NULL terminated */
 +};
 +
 +s_surf_model_description_t surf_storage_model_description[] = {
 +  {"default",
 +   "Simplistic storage model.",
 +   surf_storage_model_init_default},
 +  {NULL, NULL,  NULL}      /* this array must be NULL terminated */
 +};
 +
 +#ifdef CONTEXT_THREADS
 +static xbt_parmap_t surf_parmap = NULL; /* parallel map on models */
 +#endif
 +
 +static double *surf_mins = NULL; /* return value of share_resources for each model */
 +static int surf_min_index;       /* current index in surf_mins */
 +static double min;               /* duration determined by surf_solve */
 +
 +double NOW = 0;
 +
 +double surf_get_clock(void)
 +{
 +  return NOW;
 +}
 +
-   watched_hosts_lib = xbt_dict_new();
 +#ifdef _XBT_WIN32
 +# define FILE_DELIM "\\"
 +#else
 +# define FILE_DELIM "/"         /* FIXME: move to better location */
 +#endif
 +
 +FILE *surf_fopen(const char *name, const char *mode)
 +{
 +  unsigned int cpt;
 +  char *path_elm = NULL;
 +  char *buff;
 +  FILE *file = NULL;
 +
 +  xbt_assert(name);
 +
 +  if (__surf_is_absolute_file_path(name))       /* don't mess with absolute file names */
 +    return fopen(name, mode);
 +
 +  /* search relative files in the path */
 +  xbt_dynar_foreach(surf_path, cpt, path_elm) {
 +    buff = bprintf("%s" FILE_DELIM "%s", path_elm, name);
 +    file = fopen(buff, mode);
 +    free(buff);
 +
 +    if (file)
 +      return file;
 +  }
 +  return NULL;
 +}
 +
 +/*
 + * Returns the initial path. On Windows the initial path is
 + * the current directory for the current process in the other
 + * case the function returns "./" that represents the current
 + * directory on Unix/Linux platforms.
 + */
 +
 +const char *__surf_get_initial_path(void)
 +{
 +
 +#ifdef _XBT_WIN32
 +  unsigned i;
 +  char current_directory[MAX_PATH + 1] = { 0 };
 +  unsigned int len = GetCurrentDirectory(MAX_PATH + 1, current_directory);
 +  char root[4] = { 0 };
 +
 +  if (!len)
 +    return NULL;
 +
 +  strncpy(root, current_directory, 3);
 +
 +  for (i = 0; i < MAX_DRIVE; i++) {
 +    if (toupper(root[0]) == disk_drives_letter_table[i][0])
 +      return disk_drives_letter_table[i];
 +  }
 +
 +  return NULL;
 +#else
 +  return "./";
 +#endif
 +}
 +
 +/* The __surf_is_absolute_file_path() returns 1 if
 + * file_path is a absolute file path, in the other
 + * case the function returns 0.
 + */
 +int __surf_is_absolute_file_path(const char *file_path)
 +{
 +#ifdef _XBT_WIN32
 +  WIN32_FIND_DATA wfd = { 0 };
 +  HANDLE hFile = FindFirstFile(file_path, &wfd);
 +
 +  if (INVALID_HANDLE_VALUE == hFile)
 +    return 0;
 +
 +  FindClose(hFile);
 +  return 1;
 +#else
 +  return (file_path[0] == '/');
 +#endif
 +}
 +
 +/** Displays the long description of all registered models, and quit */
 +void model_help(const char *category, s_surf_model_description_t * table)
 +{
 +  int i;
 +  printf("Long description of the %s models accepted by this simulator:\n",
 +         category);
 +  for (i = 0; table[i].name; i++)
 +    printf("  %s: %s\n", table[i].name, table[i].description);
 +}
 +
 +int find_model_description(s_surf_model_description_t * table,
 +                           const char *name)
 +{
 +  int i;
 +  char *name_list = NULL;
 +
 +  for (i = 0; table[i].name; i++)
 +    if (!strcmp(name, table[i].name)) {
 +      return i;
 +    }
 +  name_list = strdup(table[0].name);
 +  for (i = 1; table[i].name; i++) {
 +    name_list = (char *) xbt_realloc(name_list, strlen(name_list) + strlen(table[i].name) + 3);
 +    strcat(name_list, ", ");
 +    strcat(name_list, table[i].name);
 +  }
 +  xbt_die("Model '%s' is invalid! Valid models are: %s.", name, name_list);
 +  return -1;
 +}
 +
 +static XBT_INLINE void routing_asr_host_free(void *p)
 +{
 +  delete ((RoutingEdgePtr) p);
 +}
 +
 +static XBT_INLINE void routing_asr_prop_free(void *p)
 +{
 +  xbt_dict_t elm = (xbt_dict_t) p;
 +  xbt_dict_free(&elm);
 +}
 +
 +static XBT_INLINE void surf_cpu_free(void *r)
 +{
 +  delete dynamic_cast<CpuPtr>(static_cast<ResourcePtr>(r));
 +}
 +
 +static XBT_INLINE void surf_link_free(void *r)
 +{
 +  delete dynamic_cast<NetworkCm02LinkPtr>(static_cast<ResourcePtr>(r));
 +}
 +
 +static XBT_INLINE void surf_workstation_free(void *r)
 +{
 +  delete dynamic_cast<WorkstationCLM03Ptr>(static_cast<ResourcePtr>(r));
 +}
 +
 +
 +void sg_version(int *ver_major,int *ver_minor,int *ver_patch) {
 +  *ver_major = SIMGRID_VERSION_MAJOR;
 +  *ver_minor = SIMGRID_VERSION_MINOR;
 +  *ver_patch = SIMGRID_VERSION_PATCH;
 +}
 +
 +void surf_init(int *argc, char **argv)
 +{
 +  XBT_DEBUG("Create all Libs");
 +  host_lib = xbt_lib_new();
 +  link_lib = xbt_lib_new();
 +  as_router_lib = xbt_lib_new();
 +  storage_lib = xbt_lib_new();
 +  storage_type_lib = xbt_lib_new();
++  watched_hosts_lib = xbt_dict_new_homogeneous(NULL);
 +
 +  XBT_DEBUG("Add routing levels");
 +  ROUTING_HOST_LEVEL = xbt_lib_add_level(host_lib,routing_asr_host_free);
 +  ROUTING_ASR_LEVEL  = xbt_lib_add_level(as_router_lib,routing_asr_host_free);
 +  ROUTING_PROP_ASR_LEVEL = xbt_lib_add_level(as_router_lib,routing_asr_prop_free);
 +
 +  XBT_DEBUG("Add SURF levels");
 +  SURF_CPU_LEVEL = xbt_lib_add_level(host_lib,surf_cpu_free);
 +  SURF_WKS_LEVEL = xbt_lib_add_level(host_lib,surf_workstation_free);
 +  SURF_LINK_LEVEL = xbt_lib_add_level(link_lib,surf_link_free);
 +
 +  xbt_init(argc, argv);
 +  if (!model_list)
 +    model_list = xbt_dynar_new(sizeof(surf_model_private_t), NULL);
 +  if (!history)
 +    history = tmgr_history_new();
 +
 +#ifdef HAVE_TRACING
 +  TRACE_add_start_function(TRACE_surf_alloc);
 +  TRACE_add_end_function(TRACE_surf_release);
 +#endif
 +
 +  sg_config_init(argc, argv);
 +
 +  surf_action_init();
 +  if (MC_is_active())
 +    MC_memory_init();
 +}
 +
 +void surf_exit(void)
 +{
 +  unsigned int iter;
 +  ModelPtr model = NULL;
 +
++#ifdef HAVE_TRACING
++  TRACE_end();                  /* Just in case it was not called by the upper
++                                 * layer (or there is no upper layer) */
++#endif
++
 +  sg_config_finalize();
 +
 +  xbt_dynar_foreach(model_list, iter, model)
 +    delete model;
 +  xbt_dynar_free(&model_list);
 +  routing_exit();
 +
 +  if (maxmin_system) {
 +    lmm_system_free(maxmin_system);
 +    maxmin_system = NULL;
 +  }
 +  if (history) {
 +    tmgr_history_free(history);
 +    history = NULL;
 +  }
 +  surf_action_exit();
 +
 +#ifdef CONTEXT_THREADS
 +  xbt_parmap_destroy(surf_parmap);
 +  xbt_free(surf_mins);
 +  surf_mins = NULL;
 +#endif
-     XBT_DEBUG("Updating action(%p): remains was %lf, last_update was: %lf", this, m_remains, m_lastUpdate);
++  xbt_dynar_free(&host_that_restart);
 +  xbt_dynar_free(&surf_path);
 +
 +  xbt_lib_free(&host_lib);
 +  xbt_lib_free(&link_lib);
 +  xbt_lib_free(&as_router_lib);
 +  xbt_lib_free(&storage_lib);
 +  xbt_lib_free(&storage_type_lib);
 +
 +  xbt_dict_free(&watched_hosts_lib);
 +
 +  tmgr_finalize();
 +  surf_parse_lex_destroy();
 +  surf_parse_free_callbacks();
 +
 +  NOW = 0;                      /* Just in case the user plans to restart the simulation afterward */
 +}
 +/*********
 + * Model *
 + *********/
 +
 +Model::Model(string name)
 + : m_name(name), m_resOnCB(0), m_resOffCB(0),
 +   m_actSuspendCB(0), m_actCancelCB(0), m_actResumeCB(0),
 +   p_maxminSystem(0)
 +{
 +  ActionPtr action;
 +  p_readyActionSet = xbt_swag_new(xbt_swag_offset(*action, p_stateHookup));
 +  p_runningActionSet = xbt_swag_new(xbt_swag_offset(*action, p_stateHookup));
 +  p_failedActionSet = xbt_swag_new(xbt_swag_offset(*action, p_stateHookup));
 +  p_doneActionSet = xbt_swag_new(xbt_swag_offset(*action, p_stateHookup));
 +
 +  p_modifiedSet = NULL;
 +  p_actionHeap = NULL;
 +  p_updateMechanism = UM_UNDEFINED;
 +  m_selectiveUpdate = 0;
 +}
 +
 +Model::~Model(){
 +xbt_swag_free(p_readyActionSet);
 +xbt_swag_free(p_runningActionSet);
 +xbt_swag_free(p_failedActionSet);
 +xbt_swag_free(p_doneActionSet);
 +}
 +
 +double Model::shareResources(double now)
 +{
 +  //FIXME: set the good function once and for all
 +  if (p_updateMechanism == UM_LAZY)
 +      return shareResourcesLazy(now);
 +  else if (p_updateMechanism == UM_FULL)
 +      return shareResourcesFull(now);
 +  else
 +      xbt_die("Invalid cpu update mechanism!");
 +}
 +
 +double Model::shareResourcesLazy(double now)
 +{
 +  ActionLmmPtr action = NULL;
 +  double min = -1;
 +  double value;
 +
 +  XBT_DEBUG
 +      ("Before share resources, the size of modified actions set is %d",
 +       xbt_swag_size(p_modifiedSet));
 +
 +  lmm_solve(p_maxminSystem);
 +
 +  XBT_DEBUG
 +      ("After share resources, The size of modified actions set is %d",
 +       xbt_swag_size(p_modifiedSet));
 +
 +  while((action = static_cast<ActionLmmPtr>(xbt_swag_extract(p_modifiedSet)))) {
 +    int max_dur_flag = 0;
 +
 +    if (action->p_stateSet != p_runningActionSet)
 +      continue;
 +
 +    /* bogus priority, skip it */
 +    if (action->m_priority <= 0)
 +      continue;
 +
 +    action->updateRemainingLazy(now);
 +
 +    min = -1;
 +    value = lmm_variable_getvalue(action->p_variable);
 +    if (value > 0) {
 +      if (action->m_remains > 0) {
 +        value = action->m_remains / value;
 +        min = now + value;
 +      } else {
 +        value = 0.0;
 +        min = now;
 +      }
 +    }
 +
 +    if ((action->m_maxDuration != NO_MAX_DURATION)
 +        && (min == -1
 +            || action->m_start +
 +            action->m_maxDuration < min)) {
 +      min = action->m_start +
 +          action->m_maxDuration;
 +      max_dur_flag = 1;
 +    }
 +
 +    XBT_DEBUG("Action(%p) Start %lf Finish %lf Max_duration %lf", action,
 +        action->m_start, now + value,
 +        action->m_maxDuration);
 +
 +    if (min != -1) {
 +      action->heapRemove(p_actionHeap);
 +      action->heapInsert(p_actionHeap, 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(p_actionHeap) > 0)
 +    min = xbt_heap_maxkey(p_actionHeap) - now;
 +  else
 +    min = -1;
 +
 +  XBT_DEBUG("The minimum with the HEAP %lf", min);
 +
 +  return min;
 +}
 +
 +double Model::shareResourcesFull(double now) {
 +  THROW_UNIMPLEMENTED;
 +}
 +
 +
 +double Model::shareResourcesMaxMin(xbt_swag_t running_actions,
 +                          lmm_system_t sys,
 +                          void (*solve) (lmm_system_t))
 +{
 +  void *_action = NULL;
 +  ActionLmmPtr action = NULL;
 +  double min = -1;
 +  double value = -1;
 +
 +  solve(sys);
 +
 +  xbt_swag_foreach(_action, running_actions) {
 +    action = dynamic_cast<ActionLmmPtr>(static_cast<ActionPtr>(_action));
 +    value = lmm_variable_getvalue(action->p_variable);
 +    if ((value > 0) || (action->m_maxDuration >= 0))
 +      break;
 +  }
 +
 +  if (!_action)
 +    return -1.0;
 +
 +  if (value > 0) {
 +    if (action->m_remains > 0)
 +      min = action->m_remains / value;
 +    else
 +      min = 0.0;
 +    if ((action->m_maxDuration >= 0) && (action->m_maxDuration < min))
 +      min = action->m_maxDuration;
 +  } else
 +    min = action->m_maxDuration;
 +
 +
 +  for (_action = xbt_swag_getNext(static_cast<ActionPtr>(action), running_actions->offset);
 +       _action;
 +       _action = xbt_swag_getNext(static_cast<ActionPtr>(action), running_actions->offset)) {
 +      action = dynamic_cast<ActionLmmPtr>(static_cast<ActionPtr>(_action));
 +    value = lmm_variable_getvalue(action->p_variable);
 +    if (value > 0) {
 +      if (action->m_remains > 0)
 +        value = action->m_remains / value;
 +      else
 +        value = 0.0;
 +      if (value < min) {
 +        min = value;
 +        XBT_DEBUG("Updating min (value) with %p: %f", action, min);
 +      }
 +    }
 +    if ((action->m_maxDuration >= 0) && (action->m_maxDuration < min)) {
 +      min = action->m_maxDuration;
 +      XBT_DEBUG("Updating min (duration) with %p: %f", action, min);
 +    }
 +  }
 +  XBT_DEBUG("min value : %f", min);
 +
 +  return min;
 +}
 +
 +void Model::updateActionsState(double now, double delta)
 +{
 +  if (p_updateMechanism == UM_FULL)
 +      updateActionsStateFull(now, delta);
 +  else if (p_updateMechanism == UM_LAZY)
 +      updateActionsStateLazy(now, delta);
 +  else
 +      xbt_die("Invalid cpu update mechanism!");
 +}
 +
 +void Model::updateActionsStateLazy(double now, double delta)
 +{
 +
 +}
 +
 +void Model::updateActionsStateFull(double now, double delta)
 +{
 +
 +}
 +
 +
 +void Model::addTurnedOnCallback(ResourceCallback rc)
 +{
 +  m_resOnCB = rc;
 +}
 +
 +void Model::notifyResourceTurnedOn(ResourcePtr r)
 +{
 +  m_resOnCB(r);
 +}
 +
 +void Model::addTurnedOffCallback(ResourceCallback rc)
 +{
 +  m_resOffCB = rc;
 +}
 +
 +void Model::notifyResourceTurnedOff(ResourcePtr r)
 +{
 +  m_resOffCB(r);
 +}
 +
 +void Model::addActionCancelCallback(ActionCallback ac)
 +{
 +  m_actCancelCB = ac;
 +}
 +
 +void Model::notifyActionCancel(ActionPtr a)
 +{
 +  m_actCancelCB(a);
 +}
 +
 +void Model::addActionResumeCallback(ActionCallback ac)
 +{
 +  m_actResumeCB = ac;
 +}
 +
 +void Model::notifyActionResume(ActionPtr a)
 +{
 +  m_actResumeCB(a);
 +}
 +
 +void Model::addActionSuspendCallback(ActionCallback ac)
 +{
 +  m_actSuspendCB = ac;
 +}
 +
 +void Model::notifyActionSuspend(ActionPtr a)
 +{
 +  m_actSuspendCB(a);
 +}
 +
 +
 +/************
 + * Resource *
 + ************/
 +
 +Resource::Resource(surf_model_t model, const char *name, xbt_dict_t props)
 +  : m_name(xbt_strdup(name)), m_running(true), p_model(model), m_properties(props)
 +{}
 +
 +Resource::Resource(){
 +  //FIXME:free(m_name);
 +  //FIXME:xbt_dict_free(&m_properties);
 +}
 +
 +const char *Resource::getName()
 +{
 +  return m_name;
 +}
 +
 +xbt_dict_t Resource::getProperties()
 +{
 +  return m_properties;
 +}
 +
 +e_surf_resource_state_t Resource::getState()
 +{
 +  return p_stateCurrent;
 +}
 +
 +bool Resource::isOn()
 +{
 +  return m_running;
 +}
 +
 +void Resource::turnOn()
 +{
 +  if (!m_running) {
 +    m_running = true;
 +    p_model->notifyResourceTurnedOn(this);
 +  }
 +}
 +
 +void Resource::turnOff()
 +{
 +  if (m_running) {
 +    m_running = false;
 +    p_model->notifyResourceTurnedOff(this);
 +  }
 +}
 +
 +ResourceLmm::ResourceLmm(surf_model_t model, const char *name, xbt_dict_t props,
 +                         lmm_system_t system,
 +                         double constraint_value,
 +                         tmgr_history_t history,
 +                         e_surf_resource_state_t state_init,
 +                         tmgr_trace_t state_trace,
 +                         double metric_peak,
 +                         tmgr_trace_t metric_trace)
 +  : Resource(model, name, props)
 +{
 +  p_constraint = lmm_constraint_new(system, this, constraint_value);
 +  p_stateCurrent = state_init;
 +  if (state_trace)
 +    p_stateEvent = tmgr_history_add_trace(history, state_trace, 0.0, 0, static_cast<ResourcePtr>(this));
 +  p_power.scale = 1.0;
 +  p_power.peak = metric_peak;
 +  if (metric_trace)
 +    p_power.event = tmgr_history_add_trace(history, metric_trace, 0.0, 0, static_cast<ResourcePtr>(this));
 +}
 +
 +/**********
 + * Action *
 + **********/
 +
 +const char *surf_action_state_names[6] = {
 +  "SURF_ACTION_READY",
 +  "SURF_ACTION_RUNNING",
 +  "SURF_ACTION_FAILED",
 +  "SURF_ACTION_DONE",
 +  "SURF_ACTION_TO_FREE",
 +  "SURF_ACTION_NOT_IN_THE_SYSTEM"
 +};
 +
 +/**
 + * \brief Initializes the action module of Surf.
 + */
 +void surf_action_init(void) {
 +
 +  /* the action mallocator will always provide actions of the following size,
 +   * so this size should be set to the maximum size of the surf action structures
 +   */
 +  /*FIXME:action_mallocator_allocated_size = sizeof(s_surf_action_network_CM02_t);
 +  action_mallocator = xbt_mallocator_new(65536, surf_action_mallocator_new_f,
 +      surf_action_mallocator_free_f, surf_action_mallocator_reset_f);*/
 +}
 +
 +/**
 + * \brief Uninitializes the action module of Surf.
 + */
 +void surf_action_exit(void) {
 +  //FIXME:xbt_mallocator_free(action_mallocator);
 +}
 +
 +Action::Action(){}
 +
 +Action::Action(ModelPtr model, double cost, bool failed):
 +       m_cost(cost), p_model(model), m_failed(failed), m_remains(cost),
 +       m_refcount(1), m_priority(1.0), m_maxDuration(NO_MAX_DURATION),
 +       m_start(surf_get_clock()), m_finish(-1.0)
 +{
 +  #ifdef HAVE_TRACING
 +    p_category = NULL;
 +  #endif
 +  p_stateHookup.prev = 0;
 +  p_stateHookup.next = 0;
 +  if (failed)
 +    p_stateSet = p_model->p_failedActionSet;
 +  else
 +    p_stateSet = p_model->p_runningActionSet;
 +
 +  xbt_swag_insert(this, p_stateSet);
 +}
 +
 +Action::~Action() {}
 +
 +int Action::unref(){
 +  DIE_IMPOSSIBLE;
 +}
 +
 +void Action::cancel(){
 +  DIE_IMPOSSIBLE;
 +}
 +
 +void Action::recycle(){
 +  DIE_IMPOSSIBLE;
 +}
 +
 +e_surf_action_state_t Action::getState()
 +{
 +  if (p_stateSet ==  p_model->p_readyActionSet)
 +    return SURF_ACTION_READY;
 +  if (p_stateSet ==  p_model->p_runningActionSet)
 +    return SURF_ACTION_RUNNING;
 +  if (p_stateSet ==  p_model->p_failedActionSet)
 +    return SURF_ACTION_FAILED;
 +  if (p_stateSet ==  p_model->p_doneActionSet)
 +    return SURF_ACTION_DONE;
 +  return SURF_ACTION_NOT_IN_THE_SYSTEM;
 +}
 +
 +void Action::setState(e_surf_action_state_t state)
 +{
 +  //surf_action_state_t action_state = &(action->model_type->states);
 +  XBT_IN("(%p,%s)", this, surf_action_state_names[state]);
 +  xbt_swag_remove(this, p_stateSet);
 +
 +  if (state == SURF_ACTION_READY)
 +    p_stateSet = p_model->p_readyActionSet;
 +  else if (state == SURF_ACTION_RUNNING)
 +    p_stateSet = p_model->p_runningActionSet;
 +  else if (state == SURF_ACTION_FAILED)
 +    p_stateSet = p_model->p_failedActionSet;
 +  else if (state == SURF_ACTION_DONE)
 +    p_stateSet = p_model->p_doneActionSet;
 +  else
 +    p_stateSet = NULL;
 +
 +  if (p_stateSet)
 +    xbt_swag_insert(this, p_stateSet);
 +  XBT_OUT();
 +}
 +
 +double Action::getStartTime()
 +{
 +  return m_start;
 +}
 +
 +double Action::getFinishTime()
 +{
 +  /* keep the function behavior, some models (cpu_ti) change the finish time before the action end */
 +  return m_remains == 0 ? m_finish : -1;
 +}
 +
 +double Action::getRemains()
 +{
 +  XBT_IN("(%p)", this);
 +  XBT_OUT();
 +  return m_remains;
 +}
 +
 +void Action::setData(void* data)
 +{
 +  p_data = data;
 +}
 +
 +#ifdef HAVE_TRACING
 +void Action::setCategory(const char *category)
 +{
 +  XBT_IN("(%p,%s)", this, category);
 +  p_category = xbt_strdup(category);
 +  XBT_OUT();
 +}
 +#endif
 +
 +void Action::ref(){
 +  m_refcount++;
 +}
 +
 +void ActionLmm::setMaxDuration(double duration)
 +{
 +  XBT_IN("(%p,%g)", this, duration);
 +  m_maxDuration = duration;
 +  if (p_model->p_updateMechanism == UM_LAZY)      // remove action from the heap
 +    heapRemove(p_model->p_actionHeap);
 +  XBT_OUT();
 +}
 +
 +void ActionLmm::gapRemove() {}
 +
 +void ActionLmm::setPriority(double priority)
 +{
 +  XBT_IN("(%p,%g)", this, priority);
 +  m_priority = priority;
 +  lmm_update_variable_weight(p_model->p_maxminSystem, p_variable, priority);
 +
 +  if (p_model->p_updateMechanism == UM_LAZY)
 +      heapRemove(p_model->p_actionHeap);
 +  XBT_OUT();
 +}
 +
 +void ActionLmm::cancel(){
 +  setState(SURF_ACTION_FAILED);
 +  if (p_model->p_updateMechanism == UM_LAZY) {
 +    xbt_swag_remove(this, p_model->p_modifiedSet);
 +    heapRemove(p_model->p_actionHeap);
 +  }
 +}
 +
 +int ActionLmm::unref(){
 +  m_refcount--;
 +  if (!m_refcount) {
 +      xbt_swag_remove(static_cast<ActionPtr>(this), p_stateSet);
 +      if (p_variable)
 +        lmm_variable_free(p_model->p_maxminSystem, p_variable);
 +      if (p_model->p_updateMechanism == UM_LAZY) {
 +        /* remove from heap */
 +        heapRemove(p_model->p_actionHeap);
 +        xbt_swag_remove(this, p_model->p_modifiedSet);
 +    }
 +#ifdef HAVE_TRACING
 +    xbt_free(p_category);
 +#endif
 +      delete this;
 +      return 1;
 +  }
 +  return 0;
 +}
 +
 +void ActionLmm::suspend()
 +{
 +  XBT_IN("(%p)", this);
 +  if (m_suspended != 2) {
 +    lmm_update_variable_weight(p_model->p_maxminSystem, p_variable, 0.0);
 +    m_suspended = 1;
 +    if (p_model->p_updateMechanism == UM_LAZY)
 +      heapRemove(p_model->p_actionHeap);
 +  }
 +  XBT_OUT();
 +}
 +
 +void ActionLmm::resume()
 +{
 +  XBT_IN("(%p)", this);
 +  if (m_suspended != 2) {
 +    lmm_update_variable_weight(p_model->p_maxminSystem, p_variable, m_priority);
 +    m_suspended = 0;
 +    if (p_model->p_updateMechanism == UM_LAZY)
 +      heapRemove(p_model->p_actionHeap);
 +  }
 +  XBT_OUT();
 +}
 +
 +bool ActionLmm::isSuspended()
 +{
 +  return m_suspended == 1;
 +}
 +/* 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
 + */
 +void ActionLmm::heapInsert(xbt_heap_t heap, double key, enum heap_action_type hat)
 +{
 +  m_hat = hat;
 +  xbt_heap_push(heap, this, key);
 +}
 +
 +void ActionLmm::heapRemove(xbt_heap_t heap)
 +{
 +  m_hat = NOTSET;
 +  if (m_indexHeap >= 0) {
 +    xbt_heap_remove(heap, m_indexHeap);
 +  }
 +}
 +
 +/* added to manage the communication action's heap */
 +void surf_action_lmm_update_index_heap(void *action, int i) {
 +  ((ActionLmmPtr)action)->updateIndexHeap(i);
 +}
 +
 +void ActionLmm::updateIndexHeap(int i) {
 +  m_indexHeap = i;
 +}
 +
 +double ActionLmm::getRemains()
 +{
 +  XBT_IN("(%p)", this);
 +  /* update remains before return it */
 +  if (p_model->p_updateMechanism == UM_LAZY)      /* update remains before return it */
 +    updateRemainingLazy(surf_get_clock());
 +  XBT_OUT();
 +  return m_remains;
 +}
 +
 +//FIXME split code in the right places
 +void ActionLmm::updateRemainingLazy(double now)
 +{
 +  double delta = 0.0;
 +
 +  if(p_model == static_cast<ModelPtr>(surf_network_model))
 +  {
 +    if (m_suspended != 0)
 +      return;
 +  }
 +  else
 +  {
 +    xbt_assert(p_stateSet == p_model->p_runningActionSet,
 +        "You're updating an action that is not running.");
 +
 +      /* bogus priority, skip it */
 +    xbt_assert(m_priority > 0,
 +        "You're updating an action that seems suspended.");
 +  }
 +
 +  delta = now - m_lastUpdate;
 +
 +  if (m_remains > 0) {
-     XBT_DEBUG("Updating action(%p): remains is now %lf", this, m_remains);
++    XBT_DEBUG("Updating action(%p): remains was %f, last_update was: %f", this, m_remains, m_lastUpdate);
 +    double_update(&m_remains, m_lastValue * delta);
 +
 +#ifdef HAVE_TRACING
 +    if (p_model == static_cast<ModelPtr>(surf_cpu_model) && TRACE_is_enabled()) {
 +      ResourcePtr cpu = static_cast<ResourcePtr>(lmm_constraint_id(lmm_get_cnst_from_var(p_model->p_maxminSystem, p_variable, 0)));
 +      TRACE_surf_host_set_utilization(cpu->m_name, p_category, m_lastValue, m_lastUpdate, now - m_lastUpdate);
 +    }
 +#endif
++    XBT_DEBUG("Updating action(%p): remains is now %f", this, m_remains);
 +  }
 +
 +  if(p_model == static_cast<ModelPtr>(surf_network_model))
 +  {
 +    if (m_maxDuration != NO_MAX_DURATION)
 +      double_update(&m_maxDuration, delta);
 +
 +    //FIXME: duplicated code
 +    if ((m_remains <= 0) &&
 +        (lmm_get_variable_weight(p_variable) > 0)) {
 +      m_finish = surf_get_clock();
 +      setState(SURF_ACTION_DONE);
 +      heapRemove(p_model->p_actionHeap);
 +    } else if (((m_maxDuration != NO_MAX_DURATION)
 +        && (m_maxDuration <= 0))) {
 +      m_finish = surf_get_clock();
 +      setState(SURF_ACTION_DONE);
 +      heapRemove(p_model->p_actionHeap);
 +    }
 +  }
 +
 +  m_lastUpdate = now;
 +  m_lastValue = lmm_variable_getvalue(p_variable);
 +}
 +
 +/*void Action::cancel()
 +{
 +  p_model->notifyActionCancel(this);
 +}
 +
 +void Action::suspend()
 +{
 +  p_model->notifyActionSuspend(this);
 +}
 +
 +void Action::resume()
 +{
 +  p_model->notifyActionResume(this);
 +}
 +
 +bool Action::isSuspended()
 +{
 +  return false;
 +}*/
 +
diff --combined src/surf/surf.hpp
index 862173d,0000000..874acdd
mode 100644,000000..100644
--- /dev/null
@@@ -1,331 -1,0 +1,330 @@@
- XBT_PUBLIC(void) surf_watched_hosts(void);
 +//using namespace generic;
 +
 +#ifndef SURF_MODEL_H_
 +#define SURF_MODEL_H_
 +
 +#include <xbt.h>
 +#include <string>
 +#include <vector>
 +#include <memory>
 +#include <boost/smart_ptr.hpp>
 +#include <boost/function.hpp>
 +#include <boost/functional/factory.hpp>
 +#include <boost/bind.hpp>
 +#include "surf/trace_mgr.h"
 +#include "xbt/lib.h"
 +#include "surf/surf_routing.h"
 +#include "simgrid/platf_interface.h"
 +#include "surf/surf.h"
 +#include "surf/surf_private.h"
 +
 +extern tmgr_history_t history;
 +#define NO_MAX_DURATION -1.0
 +
 +using namespace std;
 +
 +/** \ingroup SURF_simulation
 + *  \brief Return the current time
 + *
 + *  Return the current time in millisecond.
 + */
 +
 +/*********
 + * Utils *
 + *********/
 +
 +/* user-visible parameters */
 +extern double sg_tcp_gamma;
 +extern double sg_sender_gap;
 +extern double sg_latency_factor;
 +extern double sg_bandwidth_factor;
 +extern double sg_weight_S_parameter;
 +extern int sg_network_crosstraffic;
 +#ifdef HAVE_GTNETS
 +extern double sg_gtnets_jitter;
 +extern int sg_gtnets_jitter_seed;
 +#endif
 +extern xbt_dynar_t surf_path;
 +
 +#ifdef __cplusplus
 +extern "C" {
 +#endif
 +XBT_PUBLIC(double) surf_get_clock(void);
 +#ifdef __cplusplus
 +}
 +#endif
 +
 +extern double sg_sender_gap;
 +XBT_PUBLIC(int)  SURF_CPU_LEVEL;    //Surf cpu level
 +
 +int __surf_is_absolute_file_path(const char *file_path);
 +
 +/***********
 + * Classes *
 + ***********/
 +//class Model;
 +typedef Model* ModelPtr;
 +
 +//class Resource;
 +typedef Resource* ResourcePtr;
 +typedef boost::function<void (ResourcePtr r)> ResourceCallback;
 +                      
 +//class Action;
 +typedef Action* ActionPtr;
 +typedef boost::function<void (ActionPtr a)> ActionCallback;
 +
 +//class ActionLmm;
 +typedef ActionLmm* ActionLmmPtr;
 +
 +enum heap_action_type{
 +  LATENCY = 100,
 +  MAX_DURATION,
 +  NORMAL,
 +  NOTSET
 +};
 +
 +/*********
 + * Trace *
 + *********/
 +/* For the trace and trace:connect tag (store their content till the end of the parsing) */
 +XBT_PUBLIC_DATA(xbt_dict_t) traces_set_list;
 +XBT_PUBLIC_DATA(xbt_dict_t) trace_connect_list_host_avail;
 +XBT_PUBLIC_DATA(xbt_dict_t) trace_connect_list_power;
 +XBT_PUBLIC_DATA(xbt_dict_t) trace_connect_list_link_avail; 
 +XBT_PUBLIC_DATA(xbt_dict_t) trace_connect_list_bandwidth; 
 +XBT_PUBLIC_DATA(xbt_dict_t) trace_connect_list_latency;
 +
 +
 +/*********
 + * Model *
 + *********/
 +XBT_PUBLIC_DATA(xbt_dynar_t) model_list;
 +
 +class Model {
 +public:
 +  Model(string name);
 +  virtual ~Model();
 +
 +  ResourcePtr createResource(string name);
 +  ActionPtr createAction(double _cost, bool _failed);
 +  virtual double shareResources(double now);
 +  virtual double shareResourcesLazy(double now);
 +  virtual double shareResourcesFull(double now);
 +  double shareResourcesMaxMin(xbt_swag_t running_actions,
 +                                      lmm_system_t sys,
 +                                      void (*solve) (lmm_system_t));
 +  virtual void updateActionsState(double now, double delta);
 +  virtual void updateActionsStateLazy(double now, double delta);
 +  virtual void updateActionsStateFull(double now, double delta);
 +
 +  string getName() {return m_name;};
 +
 +  void addTurnedOnCallback(ResourceCallback rc);
 +  void notifyResourceTurnedOn(ResourcePtr r);
 +
 +  void addTurnedOffCallback(ResourceCallback rc);  
 +  void notifyResourceTurnedOff(ResourcePtr r);
 +
 +  void addActionCancelCallback(ActionCallback ac);
 +  void notifyActionCancel(ActionPtr a);
 +  void addActionResumeCallback(ActionCallback ac);
 +  void notifyActionResume(ActionPtr a);
 +  void addActionSuspendCallback(ActionCallback ac);  
 +  void notifyActionSuspend(ActionPtr a);
 +
 +  lmm_system_t p_maxminSystem;
 +  e_UM_t p_updateMechanism;
 +  xbt_swag_t p_modifiedSet;
 +  xbt_heap_t p_actionHeap;
 +  int m_selectiveUpdate;
 +
 +  xbt_swag_t p_readyActionSet; /**< Actions in state SURF_ACTION_READY */
 +  xbt_swag_t p_runningActionSet; /**< Actions in state SURF_ACTION_RUNNING */
 +  xbt_swag_t p_failedActionSet; /**< Actions in state SURF_ACTION_FAILED */
 +  xbt_swag_t p_doneActionSet; /**< Actions in state SURF_ACTION_DONE */
 +  string m_name;
 +
 +protected:
 +  std::vector<ActionPtr> m_failedActions, m_runningActions;
 +
 +private:
 +  ResourceCallback m_resOnCB, m_resOffCB;
 +  ActionCallback m_actCancelCB, m_actSuspendCB, m_actResumeCB;
 +};
 +
 +/************
 + * Resource *
 + ************/
 +
 +/**
 + * Resource which have a metric handled by a maxmin system
 + */
 +typedef struct {
 +  double scale;
 +  double peak;
 +  tmgr_trace_event_t event;
 +} s_surf_metric_t;
 +
 +class Resource {
 +public:
 +  Resource();
 +  Resource(ModelPtr model, const char *name, xbt_dict_t properties);
 +  virtual ~Resource() {};
 +
 +  virtual void updateState(tmgr_trace_event_t event_type, double value, double date)=0;
 +
 +  //private
 +  virtual bool isUsed()=0;
 +  //FIXME:updateActionState();
 +  //FIXME:updateResourceState();
 +  //FIXME:finilize();
 +
 +  bool isOn();
 +  void turnOn();
 +  void turnOff();
 +  void setName(string name);
 +  const char *getName();
 +  virtual xbt_dict_t getProperties();
 +
 +  ModelPtr getModel() {return p_model;};
 +  virtual e_surf_resource_state_t getState();
 +  void printModel() { std::cout << p_model->getName() << "<<plop"<<std::endl;};
 +  void *p_resource;
 +  const char *m_name;
 +  xbt_dict_t m_properties;
 +  ModelPtr p_model;
 +  e_surf_resource_state_t p_stateCurrent;
 +
 +protected:
 +
 +private:
 +  bool m_running;  
 +};
 +
 +class ResourceLmm: virtual public Resource {
 +public:
 +  ResourceLmm() {};
 +  ResourceLmm(surf_model_t model, const char *name, xbt_dict_t props,
 +                           lmm_system_t system,
 +                           double constraint_value,
 +                           tmgr_history_t history,
 +                           e_surf_resource_state_t state_init,
 +                           tmgr_trace_t state_trace,
 +                           double metric_peak,
 +                           tmgr_trace_t metric_trace);
 +  lmm_constraint_t p_constraint;
 +  tmgr_trace_event_t p_stateEvent;
 +  s_surf_metric_t p_power;
 +};
 +
 +/**********
 + * Action *
 + **********/
 +
 +class Action {
 +public:
 +  Action();
 +  Action(ModelPtr model, double cost, bool failed);
 +  virtual ~Action();
 +  
 +  s_xbt_swag_hookup_t p_stateHookup;
 +
 +  e_surf_action_state_t getState(); /**< get the state*/
 +  virtual void setState(e_surf_action_state_t state); /**< Change state*/
 +  double getStartTime(); /**< Return the start time of an action */
 +  double getFinishTime(); /**< Return the finish time of an action */
 +  void setData(void* data);
 +
 +  void ref();
 +  virtual int unref();     /**< Specify that we don't use that action anymore. Returns true if the action was destroyed and false if someone still has references on it. */
 +  virtual void cancel();     /**< Cancel a running action */
 +  virtual void recycle();     /**< Recycle an action */
 +  
 +  virtual void suspend()=0;     /**< Suspend an action */
 +  virtual void resume()=0;     /**< Resume a suspended action */
 +  virtual bool isSuspended()=0;     /**< Return whether an action is suspended */
 +  virtual void setMaxDuration(double duration)=0;     /**< Set the max duration of an action*/
 +  virtual void setPriority(double priority)=0;     /**< Set the priority of an action */
 +#ifdef HAVE_TRACING
 +  void setCategory(const char *category); /**< Set the category of an action */
 +#endif
 +  virtual double getRemains();     /**< Get the remains of an action */
 +#ifdef HAVE_LATENCY_BOUND_TRACKING
 +  int getLatencyLimited();     /**< Return 1 if action is limited by latency, 0 otherwise */
 +#endif
 +
 +  xbt_swag_t p_stateSet;
 +
 +  double m_priority; /**< priority (1.0 by default) */
 +  bool m_failed;
 +  double m_start; /**< start time  */
 +  double m_finish; /**< finish time : this is modified during the run and fluctuates until the task is completed */
 +  double m_remains; /**< How much of that cost remains to be done in the currently running task */
 +  #ifdef HAVE_LATENCY_BOUND_TRACKING
 +  int m_latencyLimited;               /**< Set to 1 if is limited by latency, 0 otherwise */
 +  #endif
 +  double m_maxDuration; /*< max_duration (may fluctuate until the task is completed) */  
 +  char *p_category;               /**< tracing category for categorized resource utilization monitoring */  
 +  int    m_cost;
 +  void *p_data; /**< for your convenience */
 +protected:
 +  ModelPtr p_model;  
 +  int    m_refcount;
 +#ifdef HAVE_TRACING
 +#endif
 +  e_UM_t p_updateMechanism;
 +
 +private:
 +  int resourceUsed(void *resource_id);
 +  /* Share the resources to the actions and return in how much time
 +     the next action may terminate */
 +  double shareResources(double now);
 +  /* Update the actions' state */
 +  void updateActionsState(double now, double delta);
 +  void updateResourceState(void *id, tmgr_trace_event_t event_type,
 +                                 double value, double time);
 +
 +  xbt_swag_t p_modifiedSet;
 +  xbt_heap_t p_actionHeap;
 +  int m_selectiveUpdate;
 +};
 +
 +//FIXME:REMOVE
 +void surf_action_lmm_update_index_heap(void *action, int i);
 +
 +class ActionLmm: virtual public Action {
 +public:
 +  ActionLmm() : m_suspended(false) {
 +      p_actionListHookup.prev = 0;
 +      p_actionListHookup.next = 0;
 +  };
 +  ActionLmm(ModelPtr model, double cost, bool failed) : m_suspended(false) {
 +      p_actionListHookup.prev = 0;
 +      p_actionListHookup.next = 0;
 +  };
 +
 +  virtual void updateRemainingLazy(double now);
 +  void heapInsert(xbt_heap_t heap, double key, enum heap_action_type hat);
 +  void heapRemove(xbt_heap_t heap);
 +  double getRemains();     /**< Get the remains of an action */
 +  void updateIndexHeap(int i);
 +
 +  virtual int unref();
 +  void cancel();
 +  void suspend();
 +  void resume();
 +  bool isSuspended();
 +  void setMaxDuration(double duration);
 +  void setPriority(double priority);
 +  void gapRemove();
 +
 +  lmm_variable_t p_variable;
 +  s_xbt_swag_hookup_t p_actionListHookup;
 +  int m_indexHeap;
 +  double m_lastUpdate;
 +  double m_lastValue;
 +  enum heap_action_type m_hat;
 +  int m_suspended;
 +};
 +
 +#endif /* SURF_MODEL_H_ */
index 44867ae,0000000..8718872
mode 100644,000000..100644
--- /dev/null
@@@ -1,391 -1,0 +1,436 @@@
-       if (resource->isUsed()) {
 +#include "surf.hpp"
 +#include "workstation.hpp"
 +#include "network.hpp"
 +#include "surf_routing_cluster.hpp"
 +#include "instr/instr_private.h"
 +
 +XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(surf_kernel);
 +
 +/*********
 + * TOOLS *
 + *********/
 +extern double NOW;
 +
 +static CpuPtr get_casted_cpu(surf_resource_t resource){
 +  return dynamic_cast<CpuPtr>(static_cast<ResourcePtr>(surf_cpu_resource_priv(resource)));
 +}
 +
 +static WorkstationCLM03Ptr get_casted_workstation(surf_resource_t resource){
 +  return dynamic_cast<WorkstationCLM03Ptr>(static_cast<ResourcePtr>(surf_workstation_resource_priv(resource)));
 +}
 +
 +char *surf_routing_edge_name(sg_routing_edge_t edge){
 +  return edge->p_name;
 +}
 +
 +#ifdef CONTEXT_THREADS
 +static xbt_parmap_t surf_parmap = NULL; /* parallel map on models */
 +#endif
 +
 +static double *surf_mins = NULL; /* return value of share_resources for each model */
 +static int surf_min_index;       /* current index in surf_mins */
 +static double surf_min;               /* duration determined by surf_solve */
 +
 +void surf_presolve(void)
 +{
 +  double next_event_date = -1.0;
 +  tmgr_trace_event_t event = NULL;
 +  double value = -1.0;
 +  ResourcePtr resource = NULL;
 +  ModelPtr model = NULL;
 +  unsigned int iter;
 +
 +  XBT_DEBUG
 +      ("First Run! Let's \"purge\" events and put models in the right state");
 +  while ((next_event_date = tmgr_history_next_date(history)) != -1.0) {
 +    if (next_event_date > NOW)
 +      break;
 +    while ((event =
 +            tmgr_history_get_next_event_leq(history, next_event_date,
 +                                            &value,
 +                                            (void **) &resource))) {
 +      if (value >= 0){
 +        resource->updateState(event, value, NOW);
 +      }
 +    }
 +  }
 +  xbt_dynar_foreach(model_list, iter, model)
 +      model->updateActionsState(NOW, 0.0);
 +}
 +
 +static void surf_share_resources(surf_model_t model)
 +{
 +  double next_action_end = -1.0;
 +  int i = __sync_fetch_and_add(&surf_min_index, 1);
 +  if (strcmp(model->m_name.c_str(), "network NS3")) {
 +    XBT_DEBUG("Running for Resource [%s]", model->m_name.c_str());
 +    next_action_end = model->shareResources(NOW);
 +    XBT_DEBUG("Resource [%s] : next action end = %f",
 +        model->m_name.c_str(), next_action_end);
 +  }
 +  surf_mins[i] = next_action_end;
 +}
 +
 +static void surf_update_actions_state(surf_model_t model)
 +{
 +  model->updateActionsState(NOW, surf_min);
 +}
 +
 +double surf_solve(double max_date)
 +{
 +  surf_min = -1.0; /* duration */
 +  double next_event_date = -1.0;
 +  double model_next_action_end = -1.0;
 +  double value = -1.0;
 +  ResourcePtr resource = NULL;
 +  ModelPtr model = NULL;
 +  tmgr_trace_event_t event = NULL;
 +  unsigned int iter;
 +
++  if(!host_that_restart)
++    host_that_restart = xbt_dynar_new(sizeof(char*), NULL);
++
 +  if (max_date != -1.0 && max_date != NOW) {
 +    surf_min = max_date - NOW;
 +  }
 +
 +  XBT_DEBUG("Looking for next action end for all models except NS3");
 +
 +  if (surf_mins == NULL) {
 +    surf_mins = xbt_new(double, xbt_dynar_length(model_list));
 +  }
 +  surf_min_index = 0;
 +
 +  /* sequential version */
 +  xbt_dynar_foreach(model_list, iter, model) {
 +    surf_share_resources(static_cast<ModelPtr>(model));
 +  }
 +
 +  unsigned i;
 +  for (i = 0; i < xbt_dynar_length(model_list); i++) {
 +    if ((surf_min < 0.0 || surf_mins[i] < surf_min)
 +        && surf_mins[i] >= 0.0) {
 +      surf_min = surf_mins[i];
 +    }
 +  }
 +
 +  XBT_DEBUG("Min for resources (remember that NS3 don't update that value) : %f", surf_min);
 +
 +  XBT_DEBUG("Looking for next trace event");
 +
 +  do {
 +    XBT_DEBUG("Next TRACE event : %f", next_event_date);
 +
 +    next_event_date = tmgr_history_next_date(history);
 +
 +    if(!strcmp(surf_network_model->m_name.c_str(), "network NS3")){//FIXME: add surf_network_model->m_name &&
 +      if(next_event_date!=-1.0 && surf_min!=-1.0) {
 +        surf_min = MIN(next_event_date - NOW, surf_min);
 +      } else{
 +        surf_min = MAX(next_event_date - NOW, surf_min);
 +      }
 +
 +      XBT_DEBUG("Run for network at most %f", surf_min);
 +      // run until min or next flow
 +      model_next_action_end = surf_network_model->shareResources(surf_min);
 +
 +      XBT_DEBUG("Min for network : %f", model_next_action_end);
 +      if(model_next_action_end>=0.0)
 +        surf_min = model_next_action_end;
 +    }
 +
 +    if (next_event_date < 0.0) {
 +      XBT_DEBUG("no next TRACE event. Stop searching for it");
 +      break;
 +    }
 +
 +    if ((surf_min == -1.0) || (next_event_date > NOW + surf_min)) break;
 +
 +    XBT_DEBUG("Updating models (min = %g, NOW = %g, next_event_date = %g)", surf_min, NOW, next_event_date);
 +    while ((event =
 +            tmgr_history_get_next_event_leq(history, next_event_date,
 +                                            &value,
 +                                            (void **) &resource))) {
-              resource->p_model->m_name.c_str(), surf_min);
++      if (resource->isUsed() || xbt_dict_get_or_null(watched_hosts_lib, resource->m_name)) {
 +        surf_min = next_event_date - NOW;
 +        XBT_DEBUG
 +            ("This event will modify model state. Next event set to %f",
 +             surf_min);
 +      }
 +      /* update state of model_obj according to new value. Does not touch lmm.
 +         It will be modified if needed when updating actions */
 +      XBT_DEBUG("Calling update_resource_state for resource %s with min %lf",
- surf_action_t surf_workstation_read(surf_resource_t resource, void *ptr, size_t size, surf_file_t fd){
-   return get_casted_workstation(resource)->read(ptr, size, fd);
++             resource->m_name, surf_min);
 +      resource->updateState(event, value, next_event_date);
 +    }
 +  } while (1);
 +
 +  /* FIXME: Moved this test to here to avoid stopping simulation if there are actions running on cpus and all cpus are with availability = 0.
 +   * This may cause an infinite loop if one cpu has a trace with periodicity = 0 and the other a trace with periodicity > 0.
 +   * The options are: all traces with same periodicity(0 or >0) or we need to change the way how the events are managed */
 +  if (surf_min == -1.0) {
 +  XBT_DEBUG("No next event at all. Bail out now.");
 +    return -1.0;
 +  }
 +
 +  XBT_DEBUG("Duration set to %f", surf_min);
 +
 +  NOW = NOW + surf_min;
 +
 +  /* sequential version */
 +  xbt_dynar_foreach(model_list, iter, model) {
 +    surf_update_actions_state(model);
 +  }
 +
 +#ifdef HAVE_TRACING
 +  TRACE_paje_dump_buffer (0);
 +#endif
 +
 +  return surf_min;
 +}
 +
 +XBT_INLINE double surf_get_clock(void)
 +{
 +  return NOW;
 +}
 +
 +void routing_get_route_and_latency(sg_routing_edge_t src, sg_routing_edge_t dst,
 +                              xbt_dynar_t * route, double *latency){
 +  routing_platf->getRouteAndLatency(src, dst, route, latency);
 +}
 +
 +/*********
 + * MODEL *
 + *********/
 +
 +void *surf_as_cluster_get_backbone(AS_t as){
 +  return static_cast<AsClusterPtr>(as)->p_backbone;
 +}
 +
 +void surf_as_cluster_set_backbone(AS_t as, void* backbone){
 +  static_cast<AsClusterPtr>(as)->p_backbone = dynamic_cast<NetworkCm02LinkPtr>(static_cast<ResourcePtr>(backbone));
 +}
 +
 +const char *surf_model_name(surf_model_t model){
 +  return model->m_name.c_str();
 +}
 +
 +xbt_swag_t surf_model_done_action_set(surf_model_t model){
 +  return model->p_doneActionSet;
 +}
 +
 +xbt_swag_t surf_model_failed_action_set(surf_model_t model){
 +  return model->p_failedActionSet;
 +}
 +
 +xbt_swag_t surf_model_ready_action_set(surf_model_t model){
 +  return model->p_readyActionSet;
 +}
 +
 +xbt_swag_t surf_model_running_action_set(surf_model_t model){
 +  return model->p_runningActionSet;
 +}
 +
 +surf_action_t surf_workstation_model_execute_parallel_task(surf_workstation_model_t model,
 +                                                  int workstation_nb,
 +                                            void **workstation_list,
 +                                            double *computation_amount,
 +                                            double *communication_amount,
 +                                            double rate){
 +  return static_cast<ActionPtr>(model->executeParallelTask(workstation_nb, workstation_list, computation_amount, communication_amount, rate));
 +}
 +
 +surf_action_t surf_workstation_model_communicate(surf_workstation_model_t model, surf_resource_t src, surf_resource_t dst, double size, double rate){
 +  return model->communicate(get_casted_workstation(src), get_casted_workstation(dst), size, rate);
 +}
 +
 +xbt_dynar_t surf_workstation_model_get_route(surf_workstation_model_t model,
 +                                                   surf_resource_t src, surf_resource_t dst){
 +  return model->getRoute(get_casted_workstation(src), get_casted_workstation(dst));
 +}
 +
 +surf_action_t surf_network_model_communicate(surf_network_model_t model, sg_routing_edge_t src, sg_routing_edge_t dst, double size, double rate){
 +  return model->communicate(src, dst, size, rate);
 +}
 +
 +const char *surf_resource_name(surf_cpp_resource_t resource){
 +  return resource->m_name;
 +}
 +
 +xbt_dict_t surf_resource_get_properties(surf_cpp_resource_t resource){
 +  return resource->getProperties();
 +}
 +
 +e_surf_resource_state_t surf_resource_get_state(surf_cpp_resource_t resource){
 +  return resource->getState();
 +}
 +
 +surf_action_t surf_workstation_sleep(surf_resource_t resource, double duration){
 +  return get_casted_workstation(resource)->sleep(duration);
 +}
 +
 +double surf_workstation_get_speed(surf_resource_t resource, double load){
 +  return get_casted_workstation(resource)->getSpeed(load);
 +}
 +
 +double surf_workstation_get_available_speed(surf_resource_t resource){
 +  return get_casted_workstation(resource)->getAvailableSpeed();
 +}
 +
 +int surf_workstation_get_core(surf_resource_t resource){
 +  return get_casted_workstation(resource)->getCore();
 +}
 +
 +surf_action_t surf_workstation_execute(surf_resource_t resource, double size){
 +  return get_casted_workstation(resource)->execute(size);
 +}
 +
++double surf_workstation_get_current_power_peak(surf_resource_t resource){
++  return get_casted_workstation(resource)->getCurrentPowerPeak();
++}
++
++double surf_workstation_get_power_peak_at(surf_resource_t resource, int pstate_index){
++  return get_casted_workstation(resource)->getPowerPeakAt(pstate_index);
++}
++
++int surf_workstation_get_nb_pstates(surf_resource_t resource){
++  return get_casted_workstation(resource)->getNbPstates();
++}
++
++void surf_workstation_set_power_peak_at(surf_resource_t resource, int pstate_index){
++  return get_casted_workstation(resource)->setPowerPeakAt(pstate_index);
++}
++
++double surf_workstation_get_consumed_energy(surf_resource_t resource){
++  return get_casted_workstation(resource)->getConsumedEnergy();
++}
++
++xbt_dict_t surf_workstation_get_storage_list(surf_resource_t workstation){
++  return get_casted_workstation(workstation)->getStorageList();
++}
 +surf_action_t surf_workstation_open(surf_resource_t workstation, const char* mount, const char* path){
 +  return get_casted_workstation(workstation)->open(mount, path);
 +}
 +
 +surf_action_t surf_workstation_close(surf_resource_t workstation, surf_file_t fd){
 +  return get_casted_workstation(workstation)->close(fd);
 +}
 +
 +int surf_workstation_unlink(surf_resource_t workstation, surf_file_t fd){
 +  return get_casted_workstation(workstation)->unlink(fd);
 +}
 +
 +surf_action_t surf_workstation_ls(surf_resource_t workstation, const char* mount, const char *path){
 +  return get_casted_workstation(workstation)->ls(mount, path);
 +}
 +
 +size_t surf_workstation_get_size(surf_resource_t workstation, surf_file_t fd){
 +  return get_casted_workstation(workstation)->getSize(fd);
 +}
 +
- surf_action_t surf_workstation_write(surf_resource_t resource, const void *ptr, size_t size, surf_file_t fd){
-   return get_casted_workstation(resource)->write(ptr, size, fd);
++surf_action_t surf_workstation_read(surf_resource_t resource, surf_file_t fd, sg_storage_size_t size){
++  return get_casted_workstation(resource)->read(fd, size);
++}
++
++surf_action_t surf_workstation_write(surf_resource_t resource, surf_file_t fd, sg_storage_size_t size){
++  return get_casted_workstation(resource)->write(fd, size);
++}
++
++xbt_dynar_t surf_workstation_get_info(surf_resource_t resource, surf_file_t fd){
++  return get_casted_workstation(resource)->getInfo(fd);
 +}
 +
++sg_storage_size_t surf_workstation_get_free_size(surf_resource_t resource, const char* name){
++  return get_casted_workstation(resource)->getFreeSize(name);
++}
++sg_storage_size_t surf_workstation_get_used_size(surf_resource_t resource, const char* name){
++  return get_casted_workstation(resource)->getUsedSize(name);
 +}
 +
 +int surf_network_link_is_shared(surf_cpp_resource_t link){
 +  return dynamic_cast<NetworkCm02LinkPtr>(link)->isShared();
 +}
 +
 +double surf_network_link_get_bandwidth(surf_cpp_resource_t link){
 +  return dynamic_cast<NetworkCm02LinkPtr>(link)->getBandwidth();
 +}
 +
 +double surf_network_link_get_latency(surf_cpp_resource_t link){
 +  return dynamic_cast<NetworkCm02LinkPtr>(link)->getLatency();
 +}
 +
++xbt_dict_t surf_storage_get_content(surf_resource_t resource){
++  return dynamic_cast<StoragePtr>(static_cast<ResourcePtr>(surf_storage_resource_priv(resource)))->getContent();
++}
++
++sg_storage_size_t surf_storage_get_size(surf_resource_t resource){
++  return dynamic_cast<StoragePtr>(static_cast<ResourcePtr>(surf_storage_resource_priv(resource)))->getSize();
++}
++
 +surf_action_t surf_cpu_execute(surf_resource_t cpu, double size){
 +  return get_casted_cpu(cpu)->execute(size);
 +}
 +
 +surf_action_t surf_cpu_sleep(surf_resource_t cpu, double duration){
 +  return get_casted_cpu(cpu)->sleep(duration);
 +}
 +
 +double surf_action_get_start_time(surf_action_t action){
 +  return action->m_start;
 +}
 +
 +double surf_action_get_finish_time(surf_action_t action){
 +  return action->m_finish;
 +}
 +
 +double surf_action_get_remains(surf_action_t action){
 +  return action->getRemains();
 +}
 +
 +void surf_action_unref(surf_action_t action){
 +  action->unref();
 +}
 +
 +void surf_action_suspend(surf_action_t action){
 +  action->suspend();
 +}
 +
 +void surf_action_resume(surf_action_t action){
 +  action->resume();
 +}
 +
 +void surf_action_cancel(surf_action_t action){
 +  action->cancel();
 +}
 +
 +void surf_action_set_priority(surf_action_t action, double priority){
 +  action->setPriority(priority);
 +}
 +
 +void surf_action_set_category(surf_action_t action, const char *category){
 +  action->setCategory(category);
 +}
 +
 +void *surf_action_get_data(surf_action_t action){
 +  return action->p_data;
 +}
 +
 +void surf_action_set_data(surf_action_t action, void *data){
 +  action->p_data = data;
 +}
 +
 +e_surf_action_state_t surf_action_get_state(surf_action_t action){
 +  return action->getState();
 +}
 +
 +int surf_action_get_cost(surf_action_t action){
 +  return action->m_cost;
 +}
 +
 +surf_file_t surf_storage_action_get_file(surf_action_t action){
 +  return dynamic_cast<StorageActionPtr>(action)->p_file;
 +}
 +
 +xbt_dict_t surf_storage_action_get_ls_dict(surf_action_t action){
 +  return dynamic_cast<StorageActionPtr>(action)->p_lsDict;
 +}
diff --combined src/surf/surf_private.h
@@@ -1,4 -1,4 +1,4 @@@
- /* Copyright (c) 2004, 2005, 2006, 2007, 2008, 2009, 2010. The SimGrid Team.
+ /* Copyright (c) 2004-2013. The SimGrid Team.
   * All rights reserved.                                                     */
  
  /* This program is free software; you can redistribute it and/or modify it
  
  #define NO_MAX_DURATION -1.0
  
 +#ifdef __cplusplus
 +extern "C" {
 +#endif
 +
  extern xbt_dict_t watched_hosts_lib;
  
  extern const char *surf_action_state_names[6];
@@@ -50,30 -46,30 +50,30 @@@ typedef struct surf_model_private 
  
  } s_surf_model_private_t;
  
 -double generic_maxmin_share_resources(xbt_swag_t running_actions,
 +/*FIXME:REMOVEdouble generic_maxmin_share_resources(xbt_swag_t running_actions,
                                        size_t offset,
                                        lmm_system_t sys,
 -                                      void (*solve) (lmm_system_t));
 +                                      void (*solve) (lmm_system_t));*/
  double generic_share_resources_lazy(double now, surf_model_t model);
  
  /* Generic functions common to all models */
  void surf_action_init(void);
  void surf_action_exit(void);
  e_surf_action_state_t surf_action_state_get(surf_action_t action);      /* cannot declare inline since we use a pointer to it */
 -double surf_action_get_start_time(surf_action_t action);        /* cannot declare inline since we use a pointer to it */
 +//FIXME:DELETEdouble surf_action_get_start_time(surf_action_t action);        /* cannot declare inline since we use a pointer to it */
  double surf_action_get_finish_time(surf_action_t action);       /* cannot declare inline since we use a pointer to it */
  void surf_action_free(surf_action_t * action);
 -void surf_action_state_set(surf_action_t action,
 -                           e_surf_action_state_t state);
 -void surf_action_data_set(surf_action_t action, void *data);    /* cannot declare inline since we use a pointer to it */
 +/*FIXME:void surf_action_state_set(surf_action_t action,
 +                           e_surf_action_state_t state);*/
 +//FIXME:void surf_action_data_set(surf_action_t action, void *data);    /* cannot declare inline since we use a pointer to it */
  
  void surf_action_lmm_update_index_heap(void *action, int i); /* callback for heap management shared by cpu and net models */
 -void surf_action_lmm_heap_insert(xbt_heap_t heap, surf_action_lmm_t action,
 -    double key, enum heap_action_type hat);
 +/*FIXME:void surf_action_lmm_heap_insert(xbt_heap_t heap, surf_action_lmm_t action,
 +    double key, enum heap_action_type hat);*/
  void surf_action_lmm_heap_remove(xbt_heap_t heap,surf_action_lmm_t action);
  
  void surf_action_cancel(surf_action_t action);
 -int surf_action_unref(surf_action_t action);
 +//FIXME:removeint surf_action_unref(surf_action_t action);
  void surf_action_suspend(surf_action_t action);
  void surf_action_resume(surf_action_t action);
  int surf_action_is_suspended(surf_action_t action);
@@@ -84,6 -80,7 +84,7 @@@ void surf_action_set_category(surf_acti
                                      const char *category);
  #endif
  double surf_action_get_remains(surf_action_t action);
+ void update_resource_energy(surf_model_t model, surf_action_lmm_t action);
  void generic_update_action_remaining_lazy( surf_action_lmm_t action, double now);
  void generic_update_actions_state_lazy(double now, double delta, surf_model_t model);
  void generic_update_actions_state_full(double now, double delta, surf_model_t model);
@@@ -199,8 -196,8 +200,8 @@@ XBT_PUBLIC(void) generic_get_graph(xbt_
  /**
   * Resource protected methods
   */
 -XBT_PUBLIC(void) surfxml_bufferstack_push(int new);
 -XBT_PUBLIC(void) surfxml_bufferstack_pop(int new);
 +XBT_PUBLIC(void) surfxml_bufferstack_push(int _new);
 +XBT_PUBLIC(void) surfxml_bufferstack_pop(int _new);
  
  XBT_PUBLIC_DATA(int) surfxml_bufferstack_size;
  
  void TRACE_surf_host_set_power(double date, const char *resource, double power);
  void TRACE_surf_link_set_bandwidth(double date, const char *resource, double bandwidth);
  
 +#ifdef __cplusplus
 +}
 +#endif
  
  #endif                          /* _SURF_SURF_PRIVATE_H */
@@@ -1,7 -1,15 +1,16 @@@
 -/* Copyright (c) 2009-2013. The SimGrid Team.
++/* Copyright (c) 2009, 2010, 2011. 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. */
 +#include "surf_routing.hpp"
 +#include "surf_routing_private.hpp"
++
+ #include "simgrid/platf_interface.h"    // platform creation API internal interface
+ #include "simgrid/sg_config.h"
 -#include "surf_routing_private.h"
 -#include "surf/surf_routing.h"
  #include "surf/surfxml_parse_values.h"
- #include "surf/random_mgr.h"
  
  /**
   * @ingroup SURF_build_api
@@@ -12,14 -20,15 +21,15 @@@ xbt_lib_t host_lib
  int ROUTING_HOST_LEVEL;         //Routing level
  int SURF_CPU_LEVEL;             //Surf cpu level
  int SURF_WKS_LEVEL;             //Surf workstation level
- int SIMIX_HOST_LEVEL;           //Simix level
- int MSG_HOST_LEVEL;             //Msg level
- int SD_HOST_LEVEL;              //Simdag level
+ int SIMIX_HOST_LEVEL;           //Simix host level
+ int SIMIX_STORAGE_LEVEL;        //Simix storage level
+ int MSG_HOST_LEVEL;             //Msg host level
+ int MSG_STORAGE_LEVEL;          //Msg storage level
+ int SD_HOST_LEVEL;              //Simdag host level
+ int SD_STORAGE_LEVEL;           //Simdag storage level
  int COORD_HOST_LEVEL=0;         //Coordinates level
  int NS3_HOST_LEVEL;             //host node for ns3
  
- xbt_dict_t watched_hosts_lib;
  /**
   * @ingroup SURF_build_api
   * @brief A library containing all known links
@@@ -37,28 -46,24 +47,28 @@@ int ROUTING_PROP_ASR_LEVEL;     //Wher
  
  static xbt_dict_t random_value = NULL;
  
 +
  /** @brief Retrieve a routing edge from its name
   *
   * Routing edges are either CPU/workstation and routers, whatever
   */
 -sg_routing_edge_t sg_routing_edge_by_name_or_null(const char *name) {
 -    sg_routing_edge_t net_elm = xbt_lib_get_or_null(host_lib, name, ROUTING_HOST_LEVEL);
 -    if(!net_elm) net_elm = xbt_lib_get_or_null(as_router_lib, name, ROUTING_ASR_LEVEL);
 +RoutingEdgePtr sg_routing_edge_by_name_or_null(const char *name) {
 +  RoutingEdgePtr net_elm = (RoutingEdgePtr) xbt_lib_get_or_null(host_lib, name, ROUTING_HOST_LEVEL);
 +  if (!net_elm)
 +      net_elm = (RoutingEdgePtr) xbt_lib_get_or_null(as_router_lib, name, ROUTING_ASR_LEVEL);
    return net_elm;
  }
  
  /* Global vars */
 -routing_platf_t routing_platf = NULL;
 -AS_t current_routing = NULL;
 +RoutingPlatfPtr routing_platf = NULL;
 +AsPtr current_routing = NULL;
  
  /* global parse functions */
  extern xbt_dynar_t mount_list;
  
 +extern "C" {
  XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_route, surf, "Routing part of surf");
 +}
  
  static void routing_parse_peer(sg_platf_peer_cbarg_t peer);     /* peer bypass */
  static void routing_parse_Srandom(void);        /* random bypass */
@@@ -103,10 -108,11 +113,10 @@@ struct s_model_type routing_models[] = 
   */
  static void parse_S_host_link(sg_platf_host_link_cbarg_t host)
  {
 -  sg_routing_edge_t info = NULL;
 -  info = xbt_lib_get_or_null(host_lib, host->id, ROUTING_HOST_LEVEL);
 -  xbt_assert(info, "Host '%s' not found!",host->id);
 -  xbt_assert(current_routing->model_desc == &routing_models[SURF_MODEL_CLUSTER] ||
 -      current_routing->model_desc == &routing_models[SURF_MODEL_VIVALDI],
 +  RoutingEdgePtr info = static_cast<RoutingEdgePtr>(xbt_lib_get_or_null(host_lib, host->id, ROUTING_HOST_LEVEL));
 +  xbt_assert(info, "Host '%s' not found!", host->id);
 +  xbt_assert(current_routing->p_modelDesc == &routing_models[SURF_MODEL_CLUSTER] ||
 +      current_routing->p_modelDesc == &routing_models[SURF_MODEL_VIVALDI],
        "You have to be in model Cluster to use tag host_link!");
  
    s_surf_parsing_link_up_down_t link_up_down;
    xbt_assert(link_up_down.link_up, "Link '%s' not found!",host->link_up);
    xbt_assert(link_up_down.link_down, "Link '%s' not found!",host->link_down);
  
 -  if(!current_routing->link_up_down_list)
 -    current_routing->link_up_down_list = xbt_dynar_new(sizeof(s_surf_parsing_link_up_down_t),NULL);
 +  if(!current_routing->p_linkUpDownList)
 +    current_routing->p_linkUpDownList = xbt_dynar_new(sizeof(s_surf_parsing_link_up_down_t),NULL);
  
    // If dynar is is greater than edge id and if the host_link is already defined
 -  if(xbt_dynar_length(current_routing->link_up_down_list) > info->id &&
 -      xbt_dynar_get_as(current_routing->link_up_down_list,info->id,void*))
 +  if(xbt_dynar_length(current_routing->p_linkUpDownList) > info->m_id &&
 +      xbt_dynar_get_as(current_routing->p_linkUpDownList, info->m_id, void*))
      xbt_die("Host_link for '%s' is already defined!",host->id);
  
 -  XBT_DEBUG("Push Host_link for host '%s' to position %d",info->name,info->id);
 -  xbt_dynar_set_as(current_routing->link_up_down_list,info->id,s_surf_parsing_link_up_down_t,link_up_down);
 +  XBT_DEBUG("Push Host_link for host '%s' to position %d", info->p_name, info->m_id);
 +  xbt_dynar_set_as(current_routing->p_linkUpDownList, info->m_id, s_surf_parsing_link_up_down_t, link_up_down);
  }
  
  /**
   */
  static void parse_S_host(sg_platf_host_cbarg_t host)
  {
 -  sg_routing_edge_t info = NULL;
 -  if (current_routing->hierarchy == SURF_ROUTING_NULL)
 -    current_routing->hierarchy = SURF_ROUTING_BASE;
 +  if (current_routing->p_hierarchy == SURF_ROUTING_NULL)
 +    current_routing->p_hierarchy = SURF_ROUTING_BASE;
    xbt_assert(!xbt_lib_get_or_null(host_lib, host->id, ROUTING_HOST_LEVEL),
               "Reading a host, processing unit \"%s\" already exists", host->id);
  
 -  info = xbt_new0(s_routing_edge_t, 1);
 -  info->rc_component = current_routing;
 -  info->rc_type = SURF_NETWORK_ELEMENT_HOST;
 -  info->name = xbt_strdup(host->id);
 -  info->id = current_routing->parse_PU(current_routing, (void *) info);
 +  RoutingEdgePtr info = new RoutingEdge();
 +  info->p_rcComponent = current_routing;
 +  info->p_rcType = SURF_NETWORK_ELEMENT_HOST;
 +  info->p_name = xbt_strdup(host->id);
 +  info->m_id = current_routing->parsePU(info);
    xbt_lib_set(host_lib, host->id, ROUTING_HOST_LEVEL, (void *) info);
 -  XBT_DEBUG("Having set name '%s' id '%d'",host->id,info->id);
 +  XBT_DEBUG("Having set name '%s' id '%d'", host->id, info->m_id);
  
    if(mount_list){
      xbt_lib_set(storage_lib, host->id, ROUTING_STORAGE_HOST_LEVEL, (void *) mount_list);
   */
  static void parse_S_router(sg_platf_router_cbarg_t router)
  {
 -  sg_routing_edge_t info = NULL;
 -  if (current_routing->hierarchy == SURF_ROUTING_NULL)
 -    current_routing->hierarchy = SURF_ROUTING_BASE;
 +  if (current_routing->p_hierarchy == SURF_ROUTING_NULL)
 +    current_routing->p_hierarchy = SURF_ROUTING_BASE;
    xbt_assert(!xbt_lib_get_or_null(as_router_lib, router->id, ROUTING_ASR_LEVEL),
               "Reading a router, processing unit \"%s\" already exists",
               router->id);
  
 -  info = xbt_new0(s_routing_edge_t, 1);
 -  info->rc_component = current_routing;
 -  info->rc_type = SURF_NETWORK_ELEMENT_ROUTER;
 -  info->name = xbt_strdup(router->id);
 -  info->id = current_routing->parse_PU(current_routing, (void *) info);
 +  RoutingEdgePtr info = new RoutingEdge();
 +  info->p_rcComponent = current_routing;
 +  info->p_rcType = SURF_NETWORK_ELEMENT_ROUTER;
 +  info->p_name = xbt_strdup(router->id);
 +  info->m_id = current_routing->parsePU(info);
    xbt_lib_set(as_router_lib, router->id, ROUTING_ASR_LEVEL, (void *) info);
 -  XBT_DEBUG("Having set name '%s' id '%d'",router->id,info->id);
 +  XBT_DEBUG("Having set name '%s' id '%d'", router->id, info->m_id);
  
    if (router->coord && strcmp(router->coord, "")) {
      unsigned int cursor;
   */
  static void parse_E_route(sg_platf_route_cbarg_t route)
  {
 -  xbt_assert(current_routing->parse_route,
 +  /*FIXME:REMOVE:xbt_assert(current_routing->parse_route,
               "no defined method \"set_route\" in \"%s\"",
 -             current_routing->name);
 +             current_routing->name);*/
  
 -  current_routing->parse_route(current_routing, route);
 +  current_routing->parseRoute(route);
  }
  
  /**
   */
  static void parse_E_ASroute(sg_platf_route_cbarg_t ASroute)
  {
 -  xbt_assert(current_routing->parse_ASroute,
 +  /*FIXME:REMOVE:xbt_assert(current_routing->parse_ASroute,
               "no defined method \"set_ASroute\" in \"%s\"",
 -             current_routing->name);
 -  current_routing->parse_ASroute(current_routing, ASroute);
 +             current_routing->name);*/
 +  current_routing->parseASroute(ASroute);
  }
  
  /**
   */
  static void parse_E_bypassRoute(sg_platf_route_cbarg_t route)
  {
 -  xbt_assert(current_routing->parse_bypassroute,
 +  /*FIXME:REMOVE:xbt_assert(current_routing->parse_bypassroute,
               "Bypassing mechanism not implemented by routing '%s'",
 -             current_routing->name);
 +             current_routing->name);*/
  
 -  current_routing->parse_bypassroute(current_routing, route);
 +  current_routing->parseBypassroute(route);
  }
  
  /**
   */
  static void parse_E_bypassASroute(sg_platf_route_cbarg_t ASroute)
  {
 -  xbt_assert(current_routing->parse_bypassroute,
 +  /*FIXME:REMOVE:xbt_assert(current_routing->parse_bypassroute,
               "Bypassing mechanism not implemented by routing '%s'",
 -             current_routing->name);
 -  current_routing->parse_bypassroute(current_routing, ASroute);
 +             current_routing->name);*/
 +  current_routing->parseBypassroute(ASroute);
  }
  
  static void routing_parse_trace(sg_platf_trace_cbarg_t trace)
@@@ -312,8 -320,6 +322,6 @@@ static void routing_parse_trace_connect
    }
  }
  
- extern int _sg_init_status; /* yay, this is an horrible hack */
  /**
   * \brief Make a new routing component to the platform
   *
  void routing_AS_begin(sg_platf_AS_cbarg_t AS)
  {
    XBT_DEBUG("routing_AS_begin");
 -  AS_t new_as;
    routing_model_description_t model = NULL;
  
    xbt_assert(!xbt_lib_get_or_null
               (as_router_lib, AS->id, ROUTING_ASR_LEVEL),
               "The AS \"%s\" already exists", AS->id);
  
-   _sg_init_status = 2; /* horrible hack: direct access to the global controlling the level of configuration to prevent any further config */
+   _sg_cfg_init_status = 2; /* horrible hack: direct access to the global
+                             * controlling the level of configuration to prevent
+                             * any further config */
  
    /* search the routing model */
    switch(AS->routing){
    }
  
    /* make a new routing component */
 -  new_as = (AS_t) model->create();
 -  new_as->model_desc = model;
 -  new_as->hierarchy = SURF_ROUTING_NULL;
 -  new_as->name = xbt_strdup(AS->id);
 +  AsPtr new_as = model->create();
 +
 +  new_as->p_modelDesc = model;
 +  new_as->p_hierarchy = SURF_ROUTING_NULL;
 +  new_as->p_name = xbt_strdup(AS->id);
  
 -  sg_routing_edge_t info = NULL;
 -  info = xbt_new0(s_routing_edge_t, 1);
 +  RoutingEdgePtr info = new RoutingEdge();
  
 -  if (current_routing == NULL && routing_platf->root == NULL) {
 +  if (current_routing == NULL && routing_platf->p_root == NULL) {
  
      /* it is the first one */
 -    new_as->routing_father = NULL;
 -    routing_platf->root = new_as;
 -    info->id = -1;
 -  } else if (current_routing != NULL && routing_platf->root != NULL) {
 +    new_as->p_routingFather = NULL;
 +    routing_platf->p_root = new_as;
 +    info->m_id = -1;
 +  } else if (current_routing != NULL && routing_platf->p_root != NULL) {
  
      xbt_assert(!xbt_dict_get_or_null
 -               (current_routing->routing_sons, AS->id),
 +               (current_routing->p_routingSons, AS->id),
                 "The AS \"%s\" already exists", AS->id);
      /* it is a part of the tree */
 -    new_as->routing_father = current_routing;
 +    new_as->p_routingFather = current_routing;
      /* set the father behavior */
 -    if (current_routing->hierarchy == SURF_ROUTING_NULL)
 -      current_routing->hierarchy = SURF_ROUTING_RECURSIVE;
 +    if (current_routing->p_hierarchy == SURF_ROUTING_NULL)
 +      current_routing->p_hierarchy = SURF_ROUTING_RECURSIVE;
      /* add to the sons dictionary */
 -    xbt_dict_set(current_routing->routing_sons, AS->id,
 +    xbt_dict_set(current_routing->p_routingSons, AS->id,
                   (void *) new_as, NULL);
      /* add to the father element list */
 -    info->id = current_routing->parse_AS(current_routing, (void *) info);
 +    info->m_id = current_routing->parseAS(info);
    } else {
      THROWF(arg_error, 0, "All defined components must be belong to a AS");
    }
  
 -  info->rc_component = new_as->routing_father;
 -  info->rc_type = SURF_NETWORK_ELEMENT_AS;
 -  info->name = new_as->name;
 +  info->p_rcComponent = new_as->p_routingFather;
 +  info->p_rcType = SURF_NETWORK_ELEMENT_AS;
 +  info->p_name = new_as->p_name;
  
 -  xbt_lib_set(as_router_lib, info->name, ROUTING_ASR_LEVEL,
 +  xbt_lib_set(as_router_lib, info->p_name, ROUTING_ASR_LEVEL,
                (void *) info);
 -  XBT_DEBUG("Having set name '%s' id '%d'",new_as->name,info->id);
 +  XBT_DEBUG("Having set name '%s' id '%d'", new_as->p_name, info->m_id);
  
    /* set the new current component of the tree */
    current_routing = new_as;
 -  current_routing->net_elem = info;
 +  current_routing->p_netElem = info;
  
  }
  
@@@ -416,9 -425,9 +426,9 @@@ void routing_AS_end(sg_platf_AS_cbarg_
    if (current_routing == NULL) {
      THROWF(arg_error, 0, "Close an AS, but none was under construction");
    } else {
 -    if (current_routing->model_desc->end)
 -      current_routing->model_desc->end(current_routing);
 -    current_routing = current_routing->routing_father;
 +    if (current_routing->p_modelDesc->end)
 +      current_routing->p_modelDesc->end(current_routing);
 +    current_routing = current_routing->p_routingFather;
    }
  }
  
  /**
   * \brief Get the AS father and the first elements of the chain
   *
 - * \param src the source host name 
 + * \param src the source host name
   * \param dst the destination host name
 - * 
 - * Get the common father of the to processing units, and the first different 
 + *
 + * Get the common father of the to processing units, and the first different
   * father in the chain
   */
  static void elements_father(sg_routing_edge_t src, sg_routing_edge_t dst,
  {
    xbt_assert(src && dst, "bad parameters for \"elements_father\" method");
  #define ELEMENTS_FATHER_MAXDEPTH 16     /* increase if it is not enough */
 -  AS_t src_as, dst_as;
 -  AS_t path_src[ELEMENTS_FATHER_MAXDEPTH];
 -  AS_t path_dst[ELEMENTS_FATHER_MAXDEPTH];
 +  AsPtr src_as, dst_as;
 +  AsPtr path_src[ELEMENTS_FATHER_MAXDEPTH];
 +  AsPtr path_dst[ELEMENTS_FATHER_MAXDEPTH];
    int index_src = 0;
    int index_dst = 0;
 -  AS_t current;
 -  AS_t current_src;
 -  AS_t current_dst;
 -  AS_t father;
 +  AsPtr current;
 +  AsPtr current_src;
 +  AsPtr current_dst;
 +  AsPtr father;
  
    /* (1) find the as where the src and dst are located */
    sg_routing_edge_t src_data = src;
    sg_routing_edge_t dst_data = dst;
 -  src_as = src_data->rc_component;
 -  dst_as = dst_data->rc_component;
 +  src_as = src_data->p_rcComponent;
 +  dst_as = dst_data->p_rcComponent;
  #ifndef NDEBUG
 -  char* src_name = src_data->name;
 -  char* dst_name = dst_data->name;
 +  char* src_name = src_data->p_name;
 +  char* dst_name = dst_data->p_name;
  #endif
  
    xbt_assert(src_as && dst_as,
               "Ask for route \"from\"(%s) or \"to\"(%s) no found", src_name, dst_name);
  
    /* (2) find the path to the root routing component */
 -  for (current = src_as; current != NULL; current = current->routing_father) {
 +  for (current = src_as; current != NULL; current = current->p_routingFather) {
      if (index_src >= ELEMENTS_FATHER_MAXDEPTH)
        xbt_die("ELEMENTS_FATHER_MAXDEPTH should be increased for path_src");
      path_src[index_src++] = current;
    }
 -  for (current = dst_as; current != NULL; current = current->routing_father) {
 +  for (current = dst_as; current != NULL; current = current->p_routingFather) {
      if (index_dst >= ELEMENTS_FATHER_MAXDEPTH)
        xbt_die("ELEMENTS_FATHER_MAXDEPTH should be increased for path_dst");
      path_dst[index_dst++] = current;
  /**
   * \brief Recursive function for get_route_latency
   *
 - * \param src the source host name 
 + * \param src the source host name
   * \param dst the destination host name
   * \param *route the route where the links are stored. It is either NULL or a ready to use dynar
   * \param *latency the latency, if needed
 - * 
 + *
   * This function is called by "get_route" and "get_latency". It allows to walk
   * recursively through the ASes tree.
   */
 -static void _get_route_and_latency(sg_routing_edge_t src, sg_routing_edge_t dst,
 +static void _get_route_and_latency(RoutingEdgePtr src, RoutingEdgePtr dst,
                                     xbt_dynar_t * links, double *latency)
  {
    s_sg_platf_route_cbarg_t route;
    memset(&route,0,sizeof(route));
  
    xbt_assert(src && dst, "bad parameters for \"_get_route_latency\" method");
 -  XBT_DEBUG("Solve route/latency  \"%s\" to \"%s\"", src->name, dst->name);
 +  XBT_DEBUG("Solve route/latency  \"%s\" to \"%s\"", src->p_name, dst->p_name);
  
    /* Find how src and dst are interconnected */
 -  AS_t common_father, src_father, dst_father;
 +  AsPtr common_father, src_father, dst_father;
    elements_father(src, dst, &common_father, &src_father, &dst_father);
    XBT_DEBUG("elements_father: common father '%s' src_father '%s' dst_father '%s'",
 -      common_father->name,src_father->name,dst_father->name);
 +      common_father->p_name, src_father->p_name, dst_father->p_name);
  
    /* Check whether a direct bypass is defined */
    sg_platf_route_cbarg_t e_route_bypass = NULL;
 -  if (common_father->get_bypass_route)
 -    e_route_bypass = common_father->get_bypass_route(common_father, src, dst, latency);
 +  //FIXME:REMOVE:if (common_father->get_bypass_route)
 +
 +  e_route_bypass = common_father->getBypassRoute(src, dst, latency);
  
    /* Common ancestor is kind enough to declare a bypass route from src to dst -- use it and bail out */
    if (e_route_bypass) {
      xbt_dynar_merge(links, &e_route_bypass->link_list);
 -    generic_free_route(e_route_bypass);
 +    //FIXME:generic_free_route(e_route_bypass);
      return;
    }
  
    /* If src and dst are in the same AS, life is good */
    if (src_father == dst_father) {       /* SURF_ROUTING_BASE */
      route.link_list = *links;
 -    common_father->get_route_and_latency(common_father, src, dst, &route,latency);
 +    common_father->getRouteAndLatency(src, dst, &route, latency);
      // if vivaldi latency+=vivaldi(src,dst)
      return;
    }
  
    route.link_list = xbt_dynar_new(sizeof(sg_routing_link_t), NULL);
    // Find the net_card corresponding to father
 -  sg_routing_edge_t src_father_net_elm = src_father->net_elem;
 -  sg_routing_edge_t dst_father_net_elm = dst_father->net_elem;
 +  RoutingEdgePtr src_father_net_elm = src_father->p_netElem;
 +  RoutingEdgePtr dst_father_net_elm = dst_father->p_netElem;
  
 -  common_father->get_route_and_latency(common_father,
 -                                       src_father_net_elm, dst_father_net_elm,
 -                                       &route, latency);
 +  common_father->getRouteAndLatency(src_father_net_elm, dst_father_net_elm,
 +                                    &route, latency);
  
    xbt_assert((route.gw_src != NULL) && (route.gw_dst != NULL),
 -      "bad gateways for route from \"%s\" to \"%s\"", src->name, dst->name);
 +      "bad gateways for route from \"%s\" to \"%s\"", src->p_name, dst->p_name);
  
    sg_routing_edge_t src_gateway_net_elm = route.gw_src;
    sg_routing_edge_t dst_gateway_net_elm = route.gw_dst;
    // if vivaldi latency+=vivaldi(src_gateway,dst_gateway)
  }
  
 +AS_t surf_platf_get_root(routing_platf_t platf){
 +  return platf->p_root;
 +}
 +
 +e_surf_network_element_type_t surf_routing_edge_get_rc_type(sg_routing_edge_t edge){
 +  return edge->p_rcType;
 +}
 +
 +
  /**
   * \brief Find a route between hosts
   *
   * walk through the routing components tree and find a route between hosts
   * by calling the differents "get_route" functions in each routing component.
   */
 -void routing_get_route_and_latency(sg_routing_edge_t src,
 -                                   sg_routing_edge_t dst,
 -                                   xbt_dynar_t * route, double *latency)
 +void RoutingPlatf::getRouteAndLatency(RoutingEdgePtr src, RoutingEdgePtr dst,
 +                                   xbt_dynar_t* route, double *latency)
  {
 -  XBT_DEBUG("routing_get_route_and_latency from %s to %s",src->name,dst->name);
 +  XBT_DEBUG("routing_get_route_and_latency from %s to %s", src->p_name, dst->p_name);
    if (!*route) {
 -    xbt_dynar_reset(routing_platf->last_route);
 -    *route = routing_platf->last_route;
 +    xbt_dynar_reset(routing_platf->p_lastRoute);
 +    *route = routing_platf->p_lastRoute;
    }
  
    _get_route_and_latency(src, dst, route, latency);
  
    xbt_assert(!latency || *latency >= 0.0,
 -             "negative latency on route between \"%s\" and \"%s\"", src->name, dst->name);
 +             "negative latency on route between \"%s\" and \"%s\"", src->p_name, dst->p_name);
 +}
 +
 +xbt_dynar_t RoutingPlatf::getOneLinkRoutes(){
 +  return recursiveGetOneLinkRoutes(p_root);
  }
  
 -static xbt_dynar_t recursive_get_onelink_routes(AS_t rc)
 +xbt_dynar_t RoutingPlatf::recursiveGetOneLinkRoutes(AsPtr rc)
  {
 -  xbt_dynar_t ret = xbt_dynar_new(sizeof(onelink_t), xbt_free);
 +  xbt_dynar_t ret = xbt_dynar_new(sizeof(OnelinkPtr), xbt_free);
  
    //adding my one link routes
 -  xbt_dynar_t onelink_mine = rc->get_onelink_routes(rc);
 +  xbt_dynar_t onelink_mine = rc->getOneLinkRoutes();
    if (onelink_mine)
      xbt_dynar_merge(&ret,&onelink_mine);
  
    char *key;
    xbt_dict_cursor_t cursor = NULL;
    AS_t rc_child;
 -  xbt_dict_foreach(rc->routing_sons, cursor, key, rc_child) {
 -    xbt_dynar_t onelink_child = recursive_get_onelink_routes(rc_child);
 +  xbt_dict_foreach(rc->p_routingSons, cursor, key, rc_child) {
 +    xbt_dynar_t onelink_child = recursiveGetOneLinkRoutes(rc_child);
      if (onelink_child)
        xbt_dynar_merge(&ret,&onelink_child);
    }
    return ret;
  }
  
 -static xbt_dynar_t get_onelink_routes(void)
 -{
 -  return recursive_get_onelink_routes(routing_platf->root);
 -}
 -
  e_surf_network_element_type_t routing_get_network_element_type(const char *name)
  {
 -  sg_routing_edge_t rc = sg_routing_edge_by_name_or_null(name);
 +  RoutingEdgePtr rc = sg_routing_edge_by_name_or_null(name);
    if (rc)
 -    return rc->rc_type;
 +    return rc->p_rcType;
  
    return SURF_NETWORK_ELEMENT_NULL;
  }
  
  /**
   * \brief Generic method: create the global routing schema
 - * 
 + *
   * Make a global routing structure and set all the parsing functions.
   */
  void routing_model_create( void *loopback)
  {
    /* config the uniq global routing */
 -  routing_platf = xbt_new0(s_routing_platf_t, 1);
 -  routing_platf->root = NULL;
 -  routing_platf->get_onelink_routes = get_onelink_routes;
 -  routing_platf->loopback = loopback;
 -  routing_platf->last_route = xbt_dynar_new(sizeof(sg_routing_link_t),NULL);
 +  routing_platf = new RoutingPlatf();
 +  routing_platf->p_root = NULL;
 +  routing_platf->p_loopback = loopback;
 +  routing_platf->p_lastRoute = xbt_dynar_new(sizeof(sg_routing_link_t),NULL);
    /* no current routing at moment */
    current_routing = NULL;
  }
  /* ************************* GENERIC PARSE FUNCTIONS ************************ */
  
  void routing_cluster_add_backbone(void* bb) {
 -  xbt_assert(current_routing->model_desc == &routing_models[SURF_MODEL_CLUSTER],
 +  xbt_assert(current_routing->p_modelDesc == &routing_models[SURF_MODEL_CLUSTER],
          "You have to be in model Cluster to use tag backbone!");
 -  xbt_assert(!((as_cluster_t)current_routing)->backbone,"The backbone link is already defined!");
 -  ((as_cluster_t)current_routing)->backbone = bb;
 -  XBT_DEBUG("Add a backbone to AS '%s'",current_routing->name);
 +  xbt_assert(!surf_as_cluster_get_backbone(current_routing), "The backbone link is already defined!");
 +  surf_as_cluster_set_backbone(current_routing, bb);
 +  XBT_DEBUG("Add a backbone to AS '%s'", current_routing->p_name);
  }
  
  static void routing_parse_cabinet(sg_platf_cabinet_cbarg_t cabinet)
      s_sg_platf_host_cbarg_t host;
      memset(&host, 0, sizeof(host));
      host.initial_state = SURF_RESOURCE_ON;
-     host.power_peak = cabinet->power;
+     host.pstate = 0;
      host.power_scale = 1.0;
      host.core_amount = 1;
  
        link_id = bprintf("link_%s%d%s",cabinet->prefix,i,cabinet->suffix);
        host.id = host_id;
        link.id = link_id;
+       xbt_dynar_t power_state_list = xbt_dynar_new(sizeof(double), NULL);
+       xbt_dynar_push(power_state_list,&cabinet->power);
+       host.power_peak = power_state_list;
        sg_platf_new_host(&host);
        sg_platf_new_link(&link);
  
@@@ -811,7 -817,7 +824,7 @@@ static void routing_parse_cluster(sg_pl
    AS.routing = A_surfxml_AS_routing_Cluster;
    sg_platf_new_AS_begin(&AS);
  
 -  current_routing->link_up_down_list
 +  current_routing->p_linkUpDownList
              = xbt_dynar_new(sizeof(s_surf_parsing_link_up_down_t),NULL);
  
    //Make all hosts
          XBT_DEBUG("\tstate_file=\"\"");
        }
  
-       host.power_peak = cluster->power;
+       xbt_dynar_t power_state_list = xbt_dynar_new(sizeof(double), NULL);
+       xbt_dynar_push(power_state_list,&cluster->power);
+       host.power_peak = power_state_list;
+       host.pstate = 0;
+       //host.power_peak = cluster->power;
        host.power_scale = 1.0;
        host.core_amount = cluster->core_amount;
        host.initial_state = SURF_RESOURCE_ON;
          info.link_up = xbt_lib_get_or_null(link_lib, link_id, SURF_LINK_LEVEL);
          info.link_down = info.link_up;
        }
 -      
 -      if(cluster->limiter_link!=0){      
 +
 +      if(cluster->limiter_link!=0){
          char *tmp_link = bprintf("%s_limiter", link_id);
          XBT_DEBUG("<limiter\tid=\"%s\"\tbw=\"%f\"/>", tmp_link,
                  cluster->limiter_link);
  
 -        
 +
          memset(&link, 0, sizeof(link));
          link.id = tmp_link;
          link.bandwidth = cluster->limiter_link;
        }else{
          info.limiter_link =NULL;
        }
 -      
 -      if(cluster->loopback_bw!=0 || cluster->loopback_lat!=0){      
 +
 +      if(cluster->loopback_bw!=0 || cluster->loopback_lat!=0){
          char *tmp_link = bprintf("%s_loopback", link_id);
          XBT_DEBUG("<loopback\tid=\"%s\"\tbw=\"%f\"/>", tmp_link,
                  cluster->limiter_link);
  
 -        
 +
          memset(&link, 0, sizeof(link));
          link.id = tmp_link;
          link.bandwidth = cluster->loopback_bw;
        }else{
          info.loopback_link =NULL;
        }
 -      
 -      xbt_dynar_push(current_routing->link_up_down_list,&info);
 +
 +      xbt_dynar_push(current_routing->p_linkUpDownList, &info);
        xbt_free(link_id);
        xbt_free(host_id);
      }
          bprintf("%s%s_router%s", cluster->prefix, cluster->id,
                  cluster->suffix);
    sg_platf_new_router(&router);
 -  ((as_cluster_t)current_routing)->router = xbt_lib_get_or_null(as_router_lib, router.id, ROUTING_ASR_LEVEL);
 +  ((AsClusterPtr)current_routing)->p_router = (RoutingEdgePtr) xbt_lib_get_or_null(as_router_lib, router.id, ROUTING_ASR_LEVEL);
    free(newid);
  
    //Make the backbone
@@@ -994,23 -1005,38 +1012,37 @@@ static void routing_parse_postparse(voi
  static void routing_parse_peer(sg_platf_peer_cbarg_t peer)
  {
    char *host_id = NULL;
-   char *link_id;
+   char *link_id = NULL;
+   char *router_id = NULL;
  
    XBT_DEBUG(" ");
    host_id = HOST_PEER(peer->id);
    link_id = LINK_PEER(peer->id);
 -  current_routing->link_up_down_list
 -            = xbt_dynar_new(sizeof(s_surf_parsing_link_up_down_t),NULL);
+   router_id = ROUTER_PEER(peer->id);
+   XBT_DEBUG("<AS id=\"%s\"\trouting=\"Cluster\">", peer->id);
+   s_sg_platf_AS_cbarg_t AS = SG_PLATF_AS_INITIALIZER;
+   AS.id = peer->id;
+   AS.routing = A_surfxml_AS_routing_Cluster;
+   sg_platf_new_AS_begin(&AS);
++  current_routing->p_linkUpDownList = xbt_dynar_new(sizeof(s_surf_parsing_link_up_down_t),NULL);
  
    XBT_DEBUG("<host\tid=\"%s\"\tpower=\"%f\"/>", host_id, peer->power);
    s_sg_platf_host_cbarg_t host;
    memset(&host, 0, sizeof(host));
    host.initial_state = SURF_RESOURCE_ON;
    host.id = host_id;
-   host.power_peak = peer->power;
+   xbt_dynar_t power_state_list = xbt_dynar_new(sizeof(double), NULL);
+   xbt_dynar_push(power_state_list,&peer->power);
+   host.power_peak = power_state_list;
+   host.pstate = 0;
+   //host.power_peak = peer->power;
    host.power_scale = 1.0;
    host.power_trace = peer->availability_trace;
    host.state_trace = peer->state_trace;
    host.core_amount = 1;
-   host.coord = peer->coord;
    sg_platf_new_host(&host);
  
    s_sg_platf_link_cbarg_t link;
    host_link.link_down= link_down;
    sg_platf_new_host_link(&host_link);
  
 -  ((as_cluster_t)current_routing)->router = xbt_lib_get_or_null(as_router_lib, router.id, ROUTING_ASR_LEVEL);
+   XBT_DEBUG("<router id=\"%s\"/>", router_id);
+   s_sg_platf_router_cbarg_t router;
+   memset(&router, 0, sizeof(router));
+   router.id = router_id;
+   router.coord = peer->coord;
+   sg_platf_new_router(&router);
++  static_cast<AsClusterPtr>(current_routing)->p_router = static_cast<RoutingEdgePtr>(xbt_lib_get_or_null(as_router_lib, router.id, ROUTING_ASR_LEVEL));
+   XBT_DEBUG("</AS>");
+   sg_platf_new_AS_end();
    XBT_DEBUG(" ");
  
    //xbt_dynar_free(&tab_elements_num);
+   free(router_id);
    free(host_id);
    free(link_id);
    free(link_up);
@@@ -1206,61 -1243,56 +1249,61 @@@ void routing_register_callbacks(
   * This fuction is call by "finalize". It allow to finalize the
   * AS or routing components. It delete all the structures.
   */
 -static void finalize_rec(AS_t as) {
 +static void finalize_rec(AsPtr as) {
    xbt_dict_cursor_t cursor = NULL;
    char *key;
    AS_t elem;
  
 -  xbt_dict_foreach(as->routing_sons, cursor, key, elem) {
 +  xbt_dict_foreach(as->p_routingSons, cursor, key, elem) {
      finalize_rec(elem);
    }
  
 -  as->finalize(as);
 +  delete as;;
  }
  
  /** \brief Frees all memory allocated by the routing module */
  void routing_exit(void) {
    if (!routing_platf)
      return;
 -  xbt_dynar_free(&routing_platf->last_route);
 -  finalize_rec(routing_platf->root);
 +  xbt_dynar_free(&routing_platf->p_lastRoute);
 +  finalize_rec(routing_platf->p_root);
    xbt_free(routing_platf);
  }
  
  AS_t surf_AS_get_routing_root() {
 -  return routing_platf->root;  
 +  return routing_platf->p_root;
  }
  
 -const char *surf_AS_get_name(AS_t as) {
 -  return as->name;
 +const char *surf_AS_get_name(AsPtr as) {
 +  return as->p_name;
  }
  
 -xbt_dict_t surf_AS_get_routing_sons(AS_t as) {
 -  return as->routing_sons;
 +xbt_dict_t surf_AS_get_routing_sons(AsPtr as) {
 +  return as->p_routingSons;
  }
  
 -const char *surf_AS_get_model(AS_t as) {
 -  return as->model_desc->name;
 +const char *surf_AS_get_model(AsPtr as) {
 +  return as->p_modelDesc->name;
  }
  
 -xbt_dynar_t surf_AS_get_hosts(AS_t as) {
 -  xbt_dynar_t elms = as->index_network_elm;
 +xbt_dynar_t surf_AS_get_hosts(AsPtr as) {
 +  xbt_dynar_t elms = as->p_indexNetworkElm;
    sg_routing_edge_t relm;
    xbt_dictelm_t delm;
    int index;
    int count = xbt_dynar_length(elms);
    xbt_dynar_t res =  xbt_dynar_new(sizeof(xbt_dictelm_t), NULL);
    for (index = 0; index < count; index++) {
 -     relm = xbt_dynar_get_as(elms, index, sg_routing_edge_t);
 -     delm = xbt_lib_get_elm_or_null(host_lib, relm->name);
 +     relm = xbt_dynar_get_as(elms, index, RoutingEdgePtr);
 +     delm = xbt_lib_get_elm_or_null(host_lib, relm->p_name);
       if (delm!=NULL) {
         xbt_dynar_push(res, &delm);
       }
    }
    return res;
  }
 +
 +void surf_AS_get_graph(AS_t as, xbt_graph_t graph, xbt_dict_t nodes, xbt_dict_t edges) {
 +  as->getGraph(graph, nodes, edges);
 +}
 +
@@@ -1,19 -1,38 +1,19 @@@
- /* Copyright (c) 2009, 2010, 2011. The SimGrid Team.
+ /* Copyright (c) 2009-2013. 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. */
  
 +#include "surf_routing_dijkstra.hpp"
  #include "surf_routing_private.h"
 +#include "network.hpp"
  
  /* Global vars */
  extern routing_platf_t routing_platf;
  
 +extern "C" {
  XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_route_dijkstra, surf, "Routing part of surf -- dijkstra routing logic");
 -
 -typedef struct {
 -  s_as_t generic_routing;
 -  xbt_graph_t route_graph;      /* xbt_graph */
 -  xbt_dict_t graph_node_map;    /* map */
 -  xbt_dict_t route_cache;       /* use in cache mode */
 -  int cached;
 -} s_as_dijkstra_t, *as_dijkstra_t;
 -
 -
 -typedef struct graph_node_data {
 -  int id;
 -  int graph_id;                 /* used for caching internal graph id's */
 -} s_graph_node_data_t, *graph_node_data_t;
 -
 -typedef struct graph_node_map_element {
 -  xbt_node_t node;
 -} s_graph_node_map_element_t, *graph_node_map_element_t;
 -
 -typedef struct route_cache_element {
 -  int *pred_arr;
 -  int size;
 -} s_route_cache_element_t, *route_cache_element_t;
 +}
  
  /* Free functions */
  
@@@ -41,46 -60,10 +41,46 @@@ static void graph_edge_data_free(void *
    }
  }
  
 +AS_t model_dijkstra_create(void){
 +  return new AsDijkstra(0);
 +}
 +
 +AS_t model_dijkstracache_create(void){
 +  return new AsDijkstra(1);
 +}
 +
 +void model_dijkstra_both_end(AS_t as)
 +{
 +  AsDijkstraPtr THIS_AS = static_cast<AsDijkstraPtr>(as);
 +  xbt_node_t node = NULL;
 +  unsigned int cursor2;
 +  xbt_dynar_t nodes = NULL;
 +
 +  /* Create the topology graph */
 +  if(!THIS_AS->p_routeGraph)
 +    THIS_AS->p_routeGraph = xbt_graph_new_graph(1, NULL);
 +  if(!THIS_AS->p_graphNodeMap)
 +    THIS_AS->p_graphNodeMap = xbt_dict_new_homogeneous(&graph_node_map_elem_free);
 +
 +  if (THIS_AS->m_cached && !THIS_AS->p_routeCache)
 +    THIS_AS->p_routeCache = xbt_dict_new_homogeneous(&route_cache_elem_free);
 +
 +  /* Add the loopback if needed */
 +  if (routing_platf->p_loopback && as->p_hierarchy == SURF_ROUTING_BASE)
 +    THIS_AS->addLoopback();
 +
 +  /* initialize graph indexes in nodes after graph has been built */
 +  nodes = xbt_graph_get_nodes(THIS_AS->p_routeGraph);
 +
 +  xbt_dynar_foreach(nodes, cursor2, node) {
 +    graph_node_data_t data = (graph_node_data_t) xbt_graph_node_get_data(node);
 +    data->graph_id = cursor2;
 +  }
 +}
 +
  /* Utility functions */
  
 -static xbt_node_t route_graph_new_node(as_dijkstra_t as,
 -    int id, int graph_id)
 +xbt_node_t AsDijkstra::routeGraphNewNode(int id, int graph_id)
  {
    xbt_node_t node = NULL;
    graph_node_data_t data = NULL;
    data = xbt_new0(struct graph_node_data, 1);
    data->id = id;
    data->graph_id = graph_id;
 -  node = xbt_graph_new_node(as->route_graph, data);
 +  node = xbt_graph_new_node(p_routeGraph, data);
  
    elm = xbt_new0(struct graph_node_map_element, 1);
    elm->node = node;
 -  xbt_dict_set_ext(as->graph_node_map, (char *) (&id), sizeof(int),
 +  xbt_dict_set_ext(p_graphNodeMap, (char *) (&id), sizeof(int),
        (xbt_set_elm_t) elm, NULL);
  
    return node;
  }
  
 -static graph_node_map_element_t
 -graph_node_map_search(as_dijkstra_t as, int id)
 +graph_node_map_element_t AsDijkstra::nodeMapSearch(int id)
  {
    graph_node_map_element_t elm = (graph_node_map_element_t)
 -          xbt_dict_get_or_null_ext(as->graph_node_map,
 +          xbt_dict_get_or_null_ext(p_graphNodeMap,
                (char *) (&id),
                sizeof(int));
    return elm;
  
  /* Parsing */
  
 -static void route_new_dijkstra(as_dijkstra_t as, int src_id,
 -    int dst_id, sg_platf_route_cbarg_t e_route)
 +void AsDijkstra::newRoute(int src_id, int dst_id, sg_platf_route_cbarg_t e_route)
  {
    XBT_DEBUG("Load Route from \"%d\" to \"%d\"", src_id, dst_id);
    xbt_node_t src = NULL;
    xbt_node_t dst = NULL;
  
    graph_node_map_element_t src_elm = (graph_node_map_element_t)
 -          xbt_dict_get_or_null_ext(as->graph_node_map,
 +          xbt_dict_get_or_null_ext(p_graphNodeMap,
                (char *) (&src_id),
                sizeof(int));
    graph_node_map_element_t dst_elm = (graph_node_map_element_t)
 -          xbt_dict_get_or_null_ext(as->graph_node_map,
 +          xbt_dict_get_or_null_ext(p_graphNodeMap,
                (char *) (&dst_id),
                sizeof(int));
  
  
    /* add nodes if they don't exist in the graph */
    if (src_id == dst_id && src == NULL && dst == NULL) {
 -    src = route_graph_new_node(as, src_id, -1);
 +    src = this->routeGraphNewNode(src_id, -1);
      dst = src;
    } else {
      if (src == NULL) {
 -      src = route_graph_new_node(as, src_id, -1);
 +      src = this->routeGraphNewNode(src_id, -1);
      }
      if (dst == NULL) {
 -      dst = route_graph_new_node(as, dst_id, -1);
 +      dst = this->routeGraphNewNode(dst_id, -1);
      }
    }
  
    /* add link as edge to graph */
 -  xbt_graph_new_edge(as->route_graph, src, dst, e_route);
 +  xbt_graph_new_edge(p_routeGraph, src, dst, e_route);
  }
  
 -static void add_loopback_dijkstra(as_dijkstra_t as) {
 -  xbt_dynar_t nodes = xbt_graph_get_nodes(as->route_graph);
 +void AsDijkstra::addLoopback() {
 +  xbt_dynar_t nodes = xbt_graph_get_nodes(p_routeGraph);
  
    xbt_node_t node = NULL;
    unsigned int cursor2;
      if (!found) {
        sg_platf_route_cbarg_t e_route = xbt_new0(s_sg_platf_route_cbarg_t, 1);
        e_route->link_list = xbt_dynar_new(sizeof(sg_routing_link_t), NULL);
 -      xbt_dynar_push(e_route->link_list, &routing_platf->loopback);
 -      xbt_graph_new_edge(as->route_graph, node, node, e_route);
 +      xbt_dynar_push(e_route->link_list, &routing_platf->p_loopback);
 +      xbt_graph_new_edge(p_routeGraph, node, node, e_route);
      }
    }
  }
  
 -static void dijkstra_get_route_and_latency(AS_t as_generic,
 -    sg_routing_edge_t src, sg_routing_edge_t dst, sg_platf_route_cbarg_t route, double *lat);
 -
 -static xbt_dynar_t dijkstra_get_onelink_routes(AS_t as)
 +xbt_dynar_t AsDijkstra::getOnelinkRoutes()
  {
 -  xbt_dynar_t ret = xbt_dynar_new(sizeof(onelink_t), xbt_free);
 +  xbt_dynar_t ret = xbt_dynar_new(sizeof(OnelinkPtr), xbt_free);
    sg_platf_route_cbarg_t route = xbt_new0(s_sg_platf_route_cbarg_t,1);
    route->link_list = xbt_dynar_new(sizeof(sg_routing_link_t),NULL);
  
    int src,dst;
 -  sg_routing_edge_t src_elm, dst_elm;
 -  size_t table_size = xbt_dynar_length(as->index_network_elm);
 +  RoutingEdgePtr src_elm, dst_elm;
 +  size_t table_size = xbt_dynar_length(p_indexNetworkElm);
    for(src=0; src < table_size; src++) {
      for(dst=0; dst< table_size; dst++) {
        xbt_dynar_reset(route->link_list);
 -      src_elm = xbt_dynar_get_as(as->index_network_elm,src,sg_routing_edge_t);
 -      dst_elm = xbt_dynar_get_as(as->index_network_elm,dst,sg_routing_edge_t);
 -      dijkstra_get_route_and_latency(as, src_elm, dst_elm,route, NULL);
 +      src_elm = xbt_dynar_get_as(p_indexNetworkElm, src, RoutingEdgePtr);
 +      dst_elm = xbt_dynar_get_as(p_indexNetworkElm, dst, RoutingEdgePtr);
 +      this->getRouteAndLatency(src_elm, dst_elm,route, NULL);
  
        if (xbt_dynar_length(route->link_list) == 1) {
          void *link = *(void **) xbt_dynar_get_ptr(route->link_list, 0);
 -        onelink_t onelink = xbt_new0(s_onelink_t, 1);
 -        onelink->link_ptr = link;
 -        if (as->hierarchy == SURF_ROUTING_BASE) {
 -          onelink->src = src_elm;
 -          onelink->dst = dst_elm;
 -        } else if (as->hierarchy == SURF_ROUTING_RECURSIVE) {
 -          onelink->src = route->gw_src;
 -          onelink->dst = route->gw_dst;
 +        OnelinkPtr onelink = new Onelink();
 +        onelink->p_linkPtr = link;
 +        if (p_hierarchy == SURF_ROUTING_BASE) {
 +          onelink->p_src = src_elm;
 +          onelink->p_dst = dst_elm;
 +        } else if (p_hierarchy == SURF_ROUTING_RECURSIVE) {
 +          onelink->p_src = route->gw_src;
 +          onelink->p_dst = route->gw_dst;
          }
          xbt_dynar_push(ret, &onelink);
        }
    return ret;
  }
  
 -static void dijkstra_get_route_and_latency(AS_t asg,
 -    sg_routing_edge_t src, sg_routing_edge_t dst,
 -    sg_platf_route_cbarg_t route, double *lat)
 +void AsDijkstra::getRouteAndLatency(RoutingEdgePtr src, RoutingEdgePtr dst, sg_platf_route_cbarg_t route, double *lat)
  {
  
    /* set utils vars */
 -  as_dijkstra_t as = (as_dijkstra_t) asg;
  
 -  generic_src_dst_check(asg, src, dst);
 -  int *src_id = &(src->id);
 -  int *dst_id = &(dst->id);
 +  srcDstCheck(src, dst);
 +  int *src_id = &(src->m_id);
 +  int *dst_id = &(dst->m_id);
  
    if (!src_id || !dst_id)
 -    THROWF(arg_error,0,"No route from '%s' to '%s'",src->name,dst->name);
 +    THROWF(arg_error,0,"No route from '%s' to '%s'",src->p_name,dst->p_name);
  
    int *pred_arr = NULL;
    int src_node_id = 0;
    void *link;
    xbt_dynar_t links = NULL;
    route_cache_element_t elm = NULL;
 -  xbt_dynar_t nodes = xbt_graph_get_nodes(as->route_graph);
 +  xbt_dynar_t nodes = xbt_graph_get_nodes(p_routeGraph);
  
    /* Use the graph_node id mapping set to quickly find the nodes */
 -  graph_node_map_element_t src_elm =
 -      graph_node_map_search(as, *src_id);
 -  graph_node_map_element_t dst_elm =
 -      graph_node_map_search(as, *dst_id);
 +  graph_node_map_element_t src_elm = nodeMapSearch(*src_id);
 +  graph_node_map_element_t dst_elm = nodeMapSearch(*dst_id);
  
    src_node_id = ((graph_node_data_t)
        xbt_graph_node_get_data(src_elm->node))->graph_id;
  
      xbt_node_t node_s_v = xbt_dynar_get_as(nodes, src_node_id, xbt_node_t);
      xbt_node_t node_e_v = xbt_dynar_get_as(nodes, dst_node_id, xbt_node_t);
 -    xbt_edge_t edge =
 -        xbt_graph_get_edge(as->route_graph, node_s_v, node_e_v);
 +    xbt_edge_t edge = xbt_graph_get_edge(p_routeGraph, node_s_v, node_e_v);
  
      if (edge == NULL)
 -      THROWF(arg_error,0,"No route from '%s' to '%s'",src->name,dst->name);
 +      THROWF(arg_error, 0, "No route from '%s' to '%s'", src->p_name, dst->p_name);
  
      e_route = (sg_platf_route_cbarg_t) xbt_graph_edge_get_data(edge);
  
      xbt_dynar_foreach(links, cpt, link) {
        xbt_dynar_unshift(route->link_list, &link);
        if (lat)
 -        *lat += surf_network_model->extension.network.get_link_latency(link);
 +        *lat += dynamic_cast<NetworkCm02LinkPtr>(static_cast<ResourcePtr>(link))->getLatency();
      }
  
    }
  
 -  if (as->cached) {
 +  if (m_cached) {
      /*check if there is a cached predecessor list avail */
      elm = (route_cache_element_t)
 -            xbt_dict_get_or_null_ext(as->route_cache, (char *) (&src_id),
 +            xbt_dict_get_or_null_ext(p_routeCache, (char *) (&src_id),
                  sizeof(int));
    }
  
  
      /* apply dijkstra using the indexes from the graph's node array */
      while (xbt_heap_size(pqueue) > 0) {
 -      int *v_id = xbt_heap_pop(pqueue);
 +      int *v_id = (int *) xbt_heap_pop(pqueue);
        xbt_node_t v_node = xbt_dynar_get_as(nodes, *v_id, xbt_node_t);
        xbt_dynar_t out_edges = xbt_graph_node_get_outedges(v_node);
        xbt_edge_t edge = NULL;
  
        xbt_dynar_foreach(out_edges, cursor, edge) {
          xbt_node_t u_node = xbt_graph_edge_get_target(edge);
 -        graph_node_data_t data = xbt_graph_node_get_data(u_node);
 +        graph_node_data_t data = (graph_node_data_t) xbt_graph_node_get_data(u_node);
          int u_id = data->graph_id;
          sg_platf_route_cbarg_t tmp_e_route = (sg_platf_route_cbarg_t) xbt_graph_edge_get_data(edge);
          int cost_v_u = (tmp_e_route->link_list)->used;    /* count of links, old model assume 1 */
    }
  
    /* compose route path with links */
 -  sg_routing_edge_t gw_src = NULL, gw_dst, prev_gw_src, first_gw = NULL;
 -  sg_routing_edge_t gw_dst_net_elm = NULL, prev_gw_src_net_elm = NULL;
 +  RoutingEdgePtr gw_src = NULL, gw_dst, prev_gw_src, first_gw = NULL;
 +  RoutingEdgePtr gw_dst_net_elm = NULL, prev_gw_src_net_elm = NULL;
  
    for (v = dst_node_id; v != src_node_id; v = pred_arr[v]) {
      xbt_node_t node_pred_v =
          xbt_dynar_get_as(nodes, pred_arr[v], xbt_node_t);
      xbt_node_t node_v = xbt_dynar_get_as(nodes, v, xbt_node_t);
      xbt_edge_t edge =
 -        xbt_graph_get_edge(as->route_graph, node_pred_v, node_v);
 +        xbt_graph_get_edge(p_routeGraph, node_pred_v, node_v);
  
      if (edge == NULL)
 -      THROWF(arg_error,0,"No route from '%s' to '%s'",src->name,dst->name);
 +      THROWF(arg_error, 0, "No route from '%s' to '%s'", src->p_name, dst->p_name);
  
      prev_gw_src = gw_src;
  
      if (v == dst_node_id)
        first_gw = gw_dst;
  
 -    if (asg->hierarchy == SURF_ROUTING_RECURSIVE && v != dst_node_id
 -        && strcmp(gw_dst->name, prev_gw_src->name)) {
 +    if (p_hierarchy == SURF_ROUTING_RECURSIVE && v != dst_node_id
 +        && strcmp(gw_dst->p_name, prev_gw_src->p_name)) {
        xbt_dynar_t e_route_as_to_as=NULL;
 -      routing_get_route_and_latency(gw_dst_net_elm, prev_gw_src_net_elm, &e_route_as_to_as, NULL);
 +
 +      routing_platf->getRouteAndLatency(gw_dst_net_elm, prev_gw_src_net_elm, &e_route_as_to_as, NULL);
        if (edge == NULL)
 -        THROWF(arg_error,0,"No route from '%s' to '%s'",src->name,dst->name);
 +        THROWF(arg_error,0,"No route from '%s' to '%s'", src->p_name, dst->p_name);
        links = e_route_as_to_as;
        int pos = 0;
        xbt_dynar_foreach(links, cpt, link) {
          xbt_dynar_insert_at(route->link_list, pos, &link);
          if (lat)
 -          *lat += surf_network_model->extension.network.get_link_latency(link);
 +          *lat += dynamic_cast<NetworkCm02LinkPtr>(static_cast<ResourcePtr>(link))->getLatency();
          pos++;
        }
      }
      xbt_dynar_foreach(links, cpt, link) {
        xbt_dynar_unshift(route->link_list, &link);
        if (lat)
 -        *lat += surf_network_model->extension.network.get_link_latency(link);
 +        *lat += dynamic_cast<NetworkCm02LinkPtr>(static_cast<ResourcePtr>(link))->getLatency();
      }
      size++;
    }
  
 -  if (asg->hierarchy == SURF_ROUTING_RECURSIVE) {
 +  if (p_hierarchy == SURF_ROUTING_RECURSIVE) {
      route->gw_src = gw_src;
      route->gw_dst = first_gw;
    }
  
 -  if (as->cached && elm == NULL) {
 +  if (m_cached && elm == NULL) {
      /* add to predecessor list of the current src-host to cache */
      elm = xbt_new0(struct route_cache_element, 1);
      elm->pred_arr = pred_arr;
      elm->size = size;
 -    xbt_dict_set_ext(as->route_cache, (char *) (&src_id), sizeof(int),
 +    xbt_dict_set_ext(p_routeCache, (char *) (&src_id), sizeof(int),
          (xbt_set_elm_t) elm, NULL);
    }
  
 -  if (!as->cached)
 +  if (!m_cached)
      xbt_free(pred_arr);
  }
  
 -static void dijkstra_finalize(AS_t asg)
 +AsDijkstra::~AsDijkstra()
  {
 -  as_dijkstra_t as = (as_dijkstra_t) asg;
 -
 -  xbt_graph_free_graph(as->route_graph, &xbt_free,
 +  xbt_graph_free_graph(p_routeGraph, &xbt_free,
        &graph_edge_data_free, &xbt_free);
 -  xbt_dict_free(&as->graph_node_map);
 -  if (as->cached)
 -    xbt_dict_free(&as->route_cache);
 -
 -  model_generic_finalize(asg);
 +  xbt_dict_free(&p_graphNodeMap);
 +  if (m_cached)
 +    xbt_dict_free(&p_routeCache);
  }
  
  /* Creation routing model functions */
  
 -AS_t model_dijkstra_both_create(int cached)
 -{
 -  as_dijkstra_t new_component = (as_dijkstra_t)
 -          model_generic_create_sized(sizeof(s_as_dijkstra_t));
 +AsDijkstra::AsDijkstra() : AsGeneric(), m_cached(0) {}
  
 -  new_component->generic_routing.parse_route = model_dijkstra_both_parse_route;
 +AsDijkstra::AsDijkstra(int cached) : AsGeneric(), m_cached(cached)
 +{
 +  /*new_component->generic_routing.parse_route = model_dijkstra_both_parse_route;
    new_component->generic_routing.parse_ASroute = model_dijkstra_both_parse_route;
    new_component->generic_routing.get_route_and_latency = dijkstra_get_route_and_latency;
    new_component->generic_routing.get_onelink_routes =
        dijkstra_get_onelink_routes;
    new_component->generic_routing.get_graph = generic_get_graph;
    new_component->generic_routing.finalize = dijkstra_finalize;
 -  new_component->cached = cached;
 -
 -  return (AS_t)new_component;
 +  new_component->cached = cached;*/
  }
  
 -AS_t model_dijkstra_create(void)
 +void AsDijkstra::end()
  {
 -  return model_dijkstra_both_create(0);
 -}
 -
 -AS_t model_dijkstracache_create(void)
 -{
 -  return model_dijkstra_both_create(1);
 -}
 -
 -void model_dijkstra_both_end(AS_t as)
 -{
 -  as_dijkstra_t THIS_AS = (as_dijkstra_t) as;
 -
    xbt_node_t node = NULL;
    unsigned int cursor2;
    xbt_dynar_t nodes = NULL;
  
    /* Create the topology graph */
 -  if(!THIS_AS->route_graph)
 -    THIS_AS->route_graph = xbt_graph_new_graph(1, NULL);
 -  if(!THIS_AS->graph_node_map)
 -    THIS_AS->graph_node_map = xbt_dict_new_homogeneous(&graph_node_map_elem_free);
 +  if(!p_routeGraph)
 +      p_routeGraph = xbt_graph_new_graph(1, NULL);
 +  if(!p_graphNodeMap)
 +    p_graphNodeMap = xbt_dict_new_homogeneous(&graph_node_map_elem_free);
  
 -  if (THIS_AS->cached && !THIS_AS->route_cache)
 -    THIS_AS->route_cache = xbt_dict_new_homogeneous(&route_cache_elem_free);
 +  if (m_cached && p_routeCache)
 +    p_routeCache = xbt_dict_new_homogeneous(&route_cache_elem_free);
  
    /* Add the loopback if needed */
 -  if (routing_platf->loopback && as->hierarchy == SURF_ROUTING_BASE)
 -    add_loopback_dijkstra(THIS_AS);
 +  if (routing_platf->p_loopback && p_hierarchy == SURF_ROUTING_BASE)
 +    addLoopback();
  
    /* initialize graph indexes in nodes after graph has been built */
 -  nodes = xbt_graph_get_nodes(THIS_AS->route_graph);
 +  nodes = xbt_graph_get_nodes(p_routeGraph);
  
    xbt_dynar_foreach(nodes, cursor2, node) {
 -    graph_node_data_t data = xbt_graph_node_get_data(node);
 +    graph_node_data_t data = (graph_node_data_t) xbt_graph_node_get_data(node);
      data->graph_id = cursor2;
    }
  
  }
 -void model_dijkstra_both_parse_route (AS_t asg, sg_platf_route_cbarg_t route)
 +
 +void AsDijkstra::parseASroute(sg_platf_route_cbarg_t route)
 +{
 +  parseRoute(route);
 +}
 +
 +void AsDijkstra::parseRoute(sg_platf_route_cbarg_t route)
  {
    char *src = (char*)(route->src);
    char *dst = (char*)(route->dst);
      XBT_DEBUG("Load Route from \"%s\" to \"%s\"", src, dst);
    else{
      XBT_DEBUG("Load ASroute from \"%s(%s)\" to \"%s(%s)\"", src,
 -        route->gw_src->name, dst, route->gw_dst->name);
 +        route->gw_src->p_name, dst, route->gw_dst->p_name);
      as_route = 1;
 -    if(route->gw_dst->rc_type == SURF_NETWORK_ELEMENT_NULL)
 -      xbt_die("The gw_dst '%s' does not exist!",route->gw_dst->name);
 -    if(route->gw_src->rc_type == SURF_NETWORK_ELEMENT_NULL)
 -      xbt_die("The gw_src '%s' does not exist!",route->gw_src->name);
 +    if(route->gw_dst->p_rcType == SURF_NETWORK_ELEMENT_NULL)
 +      xbt_die("The gw_dst '%s' does not exist!",route->gw_dst->p_name);
 +    if(route->gw_src->p_rcType == SURF_NETWORK_ELEMENT_NULL)
 +      xbt_die("The gw_src '%s' does not exist!",route->gw_src->p_name);
    }
  
 -  as_dijkstra_t as = (as_dijkstra_t) asg;
 -  sg_routing_edge_t src_net_elm, dst_net_elm;
 +  RoutingEdgePtr src_net_elm, dst_net_elm;
  
    src_net_elm = sg_routing_edge_by_name_or_null(src);
    dst_net_elm = sg_routing_edge_by_name_or_null(dst);
    xbt_assert(dst_net_elm, "Network elements %s not found", dst);
  
    /* Create the topology graph */
 -  if(!as->route_graph)
 -    as->route_graph = xbt_graph_new_graph(1, NULL);
 -  if(!as->graph_node_map)
 -    as->graph_node_map = xbt_dict_new_homogeneous(&graph_node_map_elem_free);
 +  if(!p_routeGraph)
 +    p_routeGraph = xbt_graph_new_graph(1, NULL);
 +  if(!p_graphNodeMap)
 +    p_graphNodeMap = xbt_dict_new_homogeneous(&graph_node_map_elem_free);
  
 -  if (as->cached && !as->route_cache)
 -    as->route_cache = xbt_dict_new_homogeneous(&route_cache_elem_free);
 +  if (m_cached && !p_routeCache)
 +    p_routeCache = xbt_dict_new_homogeneous(&route_cache_elem_free);
  
 -  sg_platf_route_cbarg_t e_route = generic_new_extended_route(asg->hierarchy, route, 1);
 -  route_new_dijkstra(as, src_net_elm->id, dst_net_elm->id, e_route);
 +  sg_platf_route_cbarg_t e_route = newExtendedRoute(p_hierarchy, route, 1);
 +  newRoute(src_net_elm->m_id, dst_net_elm->m_id, e_route);
  
    // Symmetrical YES
    if ( (route->symmetrical == TRUE && as_route == 0)
        XBT_DEBUG("Load Route from \"%s\" to \"%s\"", dst, src);
      else
        XBT_DEBUG("Load ASroute from \"%s(%s)\" to \"%s(%s)\"", dst,
 -          route->gw_dst->name, src, route->gw_src->name);
 +          route->gw_dst->p_name, src, route->gw_src->p_name);
  
 -    xbt_dynar_t nodes = xbt_graph_get_nodes(as->route_graph);
 -    xbt_node_t node_s_v = xbt_dynar_get_as(nodes, src_net_elm->id, xbt_node_t);
 -    xbt_node_t node_e_v = xbt_dynar_get_as(nodes, dst_net_elm->id, xbt_node_t);
 +    xbt_dynar_t nodes = xbt_graph_get_nodes(p_routeGraph);
 +    xbt_node_t node_s_v = xbt_dynar_get_as(nodes, src_net_elm->m_id, xbt_node_t);
 +    xbt_node_t node_e_v = xbt_dynar_get_as(nodes, dst_net_elm->m_id, xbt_node_t);
      xbt_edge_t edge =
 -        xbt_graph_get_edge(as->route_graph, node_e_v, node_s_v);
 +        xbt_graph_get_edge(p_routeGraph, node_e_v, node_s_v);
  
      if (edge)
        THROWF(arg_error,0,"(AS)Route from '%s' to '%s' already exists",src,dst);
  
      if (route->gw_dst && route->gw_src) {
 -      sg_routing_edge_t gw_tmp;
 +      RoutingEdgePtr gw_tmp;
        gw_tmp = route->gw_src;
        route->gw_src = route->gw_dst;
        route->gw_dst = gw_tmp;
      }
 -    sg_platf_route_cbarg_t link_route_back = generic_new_extended_route(asg->hierarchy, route, 0);
 -    route_new_dijkstra(as, dst_net_elm->id, src_net_elm->id, link_route_back);
 +    sg_platf_route_cbarg_t link_route_back = newExtendedRoute(p_hierarchy, route, 0);
 +    newRoute(dst_net_elm->m_id, src_net_elm->m_id, link_route_back);
    }
    xbt_dynar_free(&route->link_list);
  }
@@@ -1,46 -1,35 +1,52 @@@
+ /* Copyright (c) 2009-2013. 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. */
  #include "surf_routing_private.h"
 +#include "surf_routing_floyd.hpp"
 +#include "network.hpp"
  
 -/* Global vars */
 -extern routing_platf_t routing_platf;
 -
 +extern "C" {
  XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_route_floyd, surf, "Routing part of surf");
 +}
  
 -#define TO_FLOYD_COST(i,j) (as->cost_table)[(i)+(j)*table_size]
 -#define TO_FLOYD_PRED(i,j) (as->predecessor_table)[(i)+(j)*table_size]
 -#define TO_FLOYD_LINK(i,j) (as->link_table)[(i)+(j)*table_size]
 +#define TO_FLOYD_COST(i,j) (p_costTable)[(i)+(j)*table_size]
 +#define TO_FLOYD_PRED(i,j) (p_predecessorTable)[(i)+(j)*table_size]
 +#define TO_FLOYD_LINK(i,j) (p_linkTable)[(i)+(j)*table_size]
  
 -/* Routing model structure */
 +AS_t model_floyd_create(void)
 +{
 +  return new AsFloyd();
 +}
  
 -typedef struct {
 -  s_as_t generic_routing;
 -  /* vars for calculate the floyd algorithm. */
 -  int *predecessor_table;
 -  double *cost_table;
 -  sg_platf_route_cbarg_t *link_table;
 -} s_as_floyd_t, *as_floyd_t;
 +void model_floyd_end(AS_t current_routing)
 +{
 +  static_cast<AsFloydPtr>(current_routing)->end();
 +}
  
 -static void floyd_get_route_and_latency(AS_t asg, sg_routing_edge_t src, sg_routing_edge_t dst,
 -    sg_platf_route_cbarg_t res, double *lat);
 +AsFloyd::AsFloyd(): AsGeneric() {
 +}
 +
 +AsFloyd::~AsFloyd(){
 +  int i, j;
 +  size_t table_size;
 +  table_size = xbt_dynar_length(p_indexNetworkElm);
 +    /* Delete link_table */
 +    for (i = 0; i < table_size; i++)
 +      for (j = 0; j < table_size; j++)
 +        generic_free_route(TO_FLOYD_LINK(i, j));
 +    xbt_free(p_linkTable);
 +    /* Delete bypass dict */
 +    xbt_dict_free(&p_bypassRoutes);
 +    /* Delete predecessor and cost table */
 +    xbt_free(p_predecessorTable);
 +    xbt_free(p_costTable);
 +}
  
  /* Business methods */
 -static xbt_dynar_t floyd_get_onelink_routes(AS_t asg)
 +xbt_dynar_t AsFloyd::getOneLinkRoutes()
  {
    xbt_dynar_t ret = xbt_dynar_new(sizeof(onelink_t), xbt_free);
    sg_platf_route_cbarg_t route =   xbt_new0(s_sg_platf_route_cbarg_t, 1);
  
    int src,dst;
    sg_routing_edge_t src_elm, dst_elm;
 -  int table_size = xbt_dynar_length(asg->index_network_elm);
 +  int table_size = xbt_dynar_length(p_indexNetworkElm);
    for(src=0; src < table_size; src++) {
      for(dst=0; dst< table_size; dst++) {
        xbt_dynar_reset(route->link_list);
 -      src_elm = xbt_dynar_get_as(asg->index_network_elm,src,sg_routing_edge_t);
 -      dst_elm = xbt_dynar_get_as(asg->index_network_elm,dst,sg_routing_edge_t);
 -      floyd_get_route_and_latency(asg, src_elm, dst_elm, route, NULL);
 +      src_elm = xbt_dynar_get_as(p_indexNetworkElm, src, RoutingEdgePtr);
 +      dst_elm = xbt_dynar_get_as(p_indexNetworkElm, dst, RoutingEdgePtr);
 +      this->getRouteAndLatency(src_elm, dst_elm, route, NULL);
  
        if (xbt_dynar_length(route->link_list) == 1) {
          void *link = *(void **) xbt_dynar_get_ptr(route->link_list, 0);
          onelink_t onelink = xbt_new0(s_onelink_t, 1);
          onelink->link_ptr = link;
 -        if (asg->hierarchy == SURF_ROUTING_BASE) {
 +        if (p_hierarchy == SURF_ROUTING_BASE) {
            onelink->src = src_elm;
            onelink->dst = dst_elm;
 -        } else if (asg->hierarchy == SURF_ROUTING_RECURSIVE) {
 +        } else if (p_hierarchy == SURF_ROUTING_RECURSIVE) {
            onelink->src = route->gw_src;
            onelink->dst = route->gw_dst;
          }
    return ret;
  }
  
 -static void floyd_get_route_and_latency(AS_t asg, sg_routing_edge_t src, sg_routing_edge_t dst,
 -    sg_platf_route_cbarg_t res, double *lat)
 +void AsFloyd::getRouteAndLatency(RoutingEdgePtr src, RoutingEdgePtr dst, sg_platf_route_cbarg_t res, double *lat)
  {
  
    /* set utils vars */
 -  as_floyd_t as = (as_floyd_t)asg;
 -  size_t table_size = xbt_dynar_length(asg->index_network_elm);
 +  size_t table_size = xbt_dynar_length(p_indexNetworkElm);
  
 -  generic_src_dst_check(asg, src, dst);
 +  this->srcDstCheck(src, dst);
  
    /* create a result route */
    xbt_dynar_t route_stack = xbt_dynar_new(sizeof(sg_platf_route_cbarg_t), NULL);
    int pred;
 -  int cur = dst->id;
 +  int cur = dst->m_id;
    do {
 -    pred = TO_FLOYD_PRED(src->id, cur);
 +    pred = TO_FLOYD_PRED(src->m_id, cur);
      if (pred == -1)
 -      THROWF(arg_error, 0, "No route from '%s' to '%s'", src->name, dst->name);
 +      THROWF(arg_error, 0, "No route from '%s' to '%s'", src->p_name, dst->p_name);
      xbt_dynar_push_as(route_stack, sg_platf_route_cbarg_t, TO_FLOYD_LINK(pred, cur));
      cur = pred;
 -  } while (cur != src->id);
 +  } while (cur != src->m_id);
  
 -  if (asg->hierarchy == SURF_ROUTING_RECURSIVE) {
 +  if (p_hierarchy == SURF_ROUTING_RECURSIVE) {
      res->gw_src = xbt_dynar_getlast_as(route_stack, sg_platf_route_cbarg_t)->gw_src;
      res->gw_dst = xbt_dynar_getfirst_as(route_stack, sg_platf_route_cbarg_t)->gw_dst;
    }
    while (!xbt_dynar_is_empty(route_stack)) {
      sg_platf_route_cbarg_t e_route = xbt_dynar_pop_as(route_stack, sg_platf_route_cbarg_t);
      xbt_dynar_t links;
 -    sg_routing_link_t link;
 +    void *link;
      unsigned int cpt;
  
 -    if (asg->hierarchy == SURF_ROUTING_RECURSIVE && prev_dst_gw != NULL
 -        && strcmp(prev_dst_gw->name, e_route->gw_src->name)) {
 +    if (p_hierarchy == SURF_ROUTING_RECURSIVE && prev_dst_gw != NULL
 +        && strcmp(prev_dst_gw->p_name, e_route->gw_src->p_name)) {
        routing_get_route_and_latency(prev_dst_gw, e_route->gw_src,
                                      &res->link_list, lat);
      }
      xbt_dynar_foreach(links, cpt, link) {
        xbt_dynar_push_as(res->link_list, sg_routing_link_t, link);
        if (lat)
 -        *lat += surf_network_model->extension.network.get_link_latency(link);
 +        *lat += dynamic_cast<NetworkCm02LinkPtr>(static_cast<ResourcePtr>(link))->getLatency();
      }
  
      prev_dst_gw = e_route->gw_dst;
    xbt_dynar_free(&route_stack);
  }
  
 -static void floyd_finalize(AS_t rc)
 -{
 -  as_floyd_t as = (as_floyd_t) rc;
 -  int i, j;
 -  size_t table_size;
 -  if (as) {
 -    table_size = xbt_dynar_length(as->generic_routing.index_network_elm);
 -    /* Delete link_table */
 -    for (i = 0; i < table_size; i++)
 -      for (j = 0; j < table_size; j++)
 -        generic_free_route(TO_FLOYD_LINK(i, j));
 -    xbt_free(as->link_table);
 -    /* Delete bypass dict */
 -    xbt_dict_free(&as->generic_routing.bypassRoutes);
 -    /* Delete predecessor and cost table */
 -    xbt_free(as->predecessor_table);
 -    xbt_free(as->cost_table);
 -
 -    model_generic_finalize(rc);
 -  }
 -}
 -
 -AS_t model_floyd_create(void)
 -{
 -  as_floyd_t new_component = (as_floyd_t)model_generic_create_sized(sizeof(s_as_floyd_t));
 -  new_component->generic_routing.parse_route = model_floyd_parse_route;
 -  new_component->generic_routing.parse_ASroute = model_floyd_parse_route;
 -  new_component->generic_routing.get_route_and_latency = floyd_get_route_and_latency;
 -  new_component->generic_routing.get_onelink_routes =
 -      floyd_get_onelink_routes;
 -  new_component->generic_routing.get_graph = generic_get_graph;
 -  new_component->generic_routing.finalize = floyd_finalize;
 -  return (AS_t)new_component;
 -}
 -
 -void model_floyd_end(AS_t current_routing)
 -{
 -
 -  as_floyd_t as =
 -      ((as_floyd_t) current_routing);
 -
 -  unsigned int i, j, a, b, c;
 -
 -  /* set the size of table routing */
 -  size_t table_size = xbt_dynar_length(as->generic_routing.index_network_elm);
 -
 -  if(!as->link_table)
 -  {
 -    /* Create Cost, Predecessor and Link tables */
 -    as->cost_table = xbt_new0(double, table_size * table_size);       /* link cost from host to host */
 -    as->predecessor_table = xbt_new0(int, table_size * table_size);  /* predecessor host numbers */
 -    as->link_table = xbt_new0(sg_platf_route_cbarg_t, table_size * table_size);    /* actual link between src and dst */
 -
 -    /* Initialize costs and predecessors */
 -    for (i = 0; i < table_size; i++)
 -      for (j = 0; j < table_size; j++) {
 -        TO_FLOYD_COST(i, j) = DBL_MAX;
 -        TO_FLOYD_PRED(i, j) = -1;
 -        TO_FLOYD_LINK(i, j) = NULL;       /* fixed, missing in the previous version */
 -      }
 -  }
 -
 -  /* Add the loopback if needed */
 -  if (routing_platf->loopback && current_routing->hierarchy == SURF_ROUTING_BASE) {
 -    for (i = 0; i < table_size; i++) {
 -      sg_platf_route_cbarg_t e_route = TO_FLOYD_LINK(i, i);
 -      if (!e_route) {
 -        e_route = xbt_new0(s_sg_platf_route_cbarg_t, 1);
 -        e_route->gw_src = NULL;
 -        e_route->gw_dst = NULL;
 -        e_route->link_list = xbt_dynar_new(sizeof(sg_routing_link_t), NULL);
 -        xbt_dynar_push(e_route->link_list, &routing_platf->loopback);
 -        TO_FLOYD_LINK(i, i) = e_route;
 -        TO_FLOYD_PRED(i, i) = i;
 -        TO_FLOYD_COST(i, i) = 1;
 -      }
 -    }
 -  }
 -  /* Calculate path costs */
 -  for (c = 0; c < table_size; c++) {
 -    for (a = 0; a < table_size; a++) {
 -      for (b = 0; b < table_size; b++) {
 -        if (TO_FLOYD_COST(a, c) < DBL_MAX && TO_FLOYD_COST(c, b) < DBL_MAX) {
 -          if (TO_FLOYD_COST(a, b) == DBL_MAX ||
 -              (TO_FLOYD_COST(a, c) + TO_FLOYD_COST(c, b) <
 -                  TO_FLOYD_COST(a, b))) {
 -            TO_FLOYD_COST(a, b) =
 -                TO_FLOYD_COST(a, c) + TO_FLOYD_COST(c, b);
 -            TO_FLOYD_PRED(a, b) = TO_FLOYD_PRED(c, b);
 -          }
 -        }
 -      }
 -    }
 -  }
 -}
 -
  static int floyd_pointer_resource_cmp(const void *a, const void *b) {
    return a != b;
  }
  
 -//FIXME: kill dupplicates in next function with full routing
 +void AsFloyd::parseASroute(sg_platf_route_cbarg_t route){
 +  parseRoute(route);
 +}
  
 -void model_floyd_parse_route(AS_t rc, sg_platf_route_cbarg_t route)
 +void AsFloyd::parseRoute(sg_platf_route_cbarg_t route)
  {
    char *src = (char*)(route->src);
    char *dst = (char*)(route->dst);
  
    int as_route = 0;
 -  as_floyd_t as = (as_floyd_t) rc;
  
    /* set the size of table routing */
 -  size_t table_size = xbt_dynar_length(rc->index_network_elm);
 -  sg_routing_edge_t src_net_elm, dst_net_elm;
 +  size_t table_size = xbt_dynar_length(p_indexNetworkElm);
 +  RoutingEdgePtr src_net_elm, dst_net_elm;
  
    src_net_elm = sg_routing_edge_by_name_or_null(src);
    dst_net_elm = sg_routing_edge_by_name_or_null(dst);
    xbt_assert(src_net_elm, "Network elements %s not found", src);
    xbt_assert(dst_net_elm, "Network elements %s not found", dst);
  
 -  if(!as->link_table)
 +  if(!p_linkTable)
    {
      int i,j;
      /* Create Cost, Predecessor and Link tables */
 -    as->cost_table = xbt_new0(double, table_size * table_size);       /* link cost from host to host */
 -    as->predecessor_table = xbt_new0(int, table_size * table_size);  /* predecessor host numbers */
 -    as->link_table = xbt_new0(sg_platf_route_cbarg_t, table_size * table_size);    /* actual link between src and dst */
 +    p_costTable = xbt_new0(double, table_size * table_size);       /* link cost from host to host */
 +    p_predecessorTable = xbt_new0(int, table_size * table_size);  /* predecessor host numbers */
 +    p_linkTable = xbt_new0(sg_platf_route_cbarg_t, table_size * table_size);    /* actual link between src and dst */
  
      /* Initialize costs and predecessors */
      for (i = 0; i < table_size; i++)
    else{
      as_route = 1;
      XBT_DEBUG("Load ASroute from \"%s(%s)\" to \"%s(%s)\"", src,
 -        route->gw_src->name, dst, route->gw_dst->name);
 -    if(route->gw_dst->rc_type == SURF_NETWORK_ELEMENT_NULL)
 -      xbt_die("The dst_gateway '%s' does not exist!",route->gw_dst->name);
 -    if(route->gw_src->rc_type == SURF_NETWORK_ELEMENT_NULL)
 -      xbt_die("The src_gateway '%s' does not exist!",route->gw_src->name);
 +        route->gw_src->p_name, dst, route->gw_dst->p_name);
 +    if(route->gw_dst->p_rcType == SURF_NETWORK_ELEMENT_NULL)
 +      xbt_die("The dst_gateway '%s' does not exist!",route->gw_dst->p_name);
 +    if(route->gw_src->p_rcType == SURF_NETWORK_ELEMENT_NULL)
 +      xbt_die("The src_gateway '%s' does not exist!",route->gw_src->p_name);
    }
  
 -  if(TO_FLOYD_LINK(src_net_elm->id, dst_net_elm->id))
 +  if(TO_FLOYD_LINK(src_net_elm->m_id, dst_net_elm->m_id))
    {
  
      char * link_name;
        xbt_dynar_push(link_route_to_test,&link);
      }
      xbt_assert(!xbt_dynar_compare(
 -        (void*)TO_FLOYD_LINK(src_net_elm->id, dst_net_elm->id)->link_list,
 -        (void*)link_route_to_test,
 +        TO_FLOYD_LINK(src_net_elm->m_id, dst_net_elm->m_id)->link_list,
 +        link_route_to_test,
          (int_f_cpvoid_cpvoid_t) floyd_pointer_resource_cmp),
          "The route between \"%s\" and \"%s\" already exists", src,dst);
    }
    else
    {
 -    TO_FLOYD_LINK(src_net_elm->id, dst_net_elm->id) =
 -        generic_new_extended_route(rc->hierarchy, route, 1);
 -    TO_FLOYD_PRED(src_net_elm->id, dst_net_elm->id) = src_net_elm->id;
 -    TO_FLOYD_COST(src_net_elm->id, dst_net_elm->id) =
 -        ((TO_FLOYD_LINK(src_net_elm->id, dst_net_elm->id))->link_list)->used;   /* count of links, old model assume 1 */
 +    TO_FLOYD_LINK(src_net_elm->m_id, dst_net_elm->m_id) =
 +        newExtendedRoute(p_hierarchy, route, 1);
 +    TO_FLOYD_PRED(src_net_elm->m_id, dst_net_elm->m_id) = src_net_elm->m_id;
 +    TO_FLOYD_COST(src_net_elm->m_id, dst_net_elm->m_id) =
 +        ((TO_FLOYD_LINK(src_net_elm->m_id, dst_net_elm->m_id))->link_list)->used;   /* count of links, old model assume 1 */
    }
  
    if ( (route->symmetrical == TRUE && as_route == 0)
        || (route->symmetrical == TRUE && as_route == 1)
    )
    {
 -    if(TO_FLOYD_LINK(dst_net_elm->id, src_net_elm->id))
 +    if(TO_FLOYD_LINK(dst_net_elm->m_id, src_net_elm->m_id))
      {
        if(!route->gw_dst && !route->gw_src)
          XBT_DEBUG("See Route from \"%s\" to \"%s\"", dst, src);
        else
          XBT_DEBUG("See ASroute from \"%s(%s)\" to \"%s(%s)\"", dst,
 -            route->gw_src->name, src, route->gw_dst->name);
 +            route->gw_src->p_name, src, route->gw_dst->p_name);
        char * link_name;
        unsigned int i;
        xbt_dynar_t link_route_to_test = xbt_dynar_new(sizeof(sg_routing_link_t), NULL);
        for(i=xbt_dynar_length(route->link_list) ;i>0 ;i--)
        {
 -        link_name = xbt_dynar_get_as(route->link_list,i-1,void *);
 +        link_name = xbt_dynar_get_as(route->link_list,i-1,char *);
          void *link = xbt_lib_get_or_null(link_lib, link_name, SURF_LINK_LEVEL);
          xbt_assert(link,"Link : '%s' doesn't exists.",link_name);
          xbt_dynar_push(link_route_to_test,&link);
        }
        xbt_assert(!xbt_dynar_compare(
 -          (void*)TO_FLOYD_LINK(dst_net_elm->id, src_net_elm->id)->link_list,
 -          (void*)link_route_to_test,
 +          TO_FLOYD_LINK(dst_net_elm->m_id, src_net_elm->m_id)->link_list,
 +          link_route_to_test,
            (int_f_cpvoid_cpvoid_t) floyd_pointer_resource_cmp),
            "The route between \"%s\" and \"%s\" already exists", src,dst);
      }
          XBT_DEBUG("Load Route from \"%s\" to \"%s\"", dst, src);
        else
          XBT_DEBUG("Load ASroute from \"%s(%s)\" to \"%s(%s)\"", dst,
 -            route->gw_src->name, src, route->gw_dst->name);
 +            route->gw_src->p_name, src, route->gw_dst->p_name);
  
 -      TO_FLOYD_LINK(dst_net_elm->id, src_net_elm->id) =
 -          generic_new_extended_route(rc->hierarchy, route, 0);
 -      TO_FLOYD_PRED(dst_net_elm->id, src_net_elm->id) = dst_net_elm->id;
 -      TO_FLOYD_COST(dst_net_elm->id, src_net_elm->id) =
 -          ((TO_FLOYD_LINK(dst_net_elm->id, src_net_elm->id))->link_list)->used;   /* count of links, old model assume 1 */
 +      TO_FLOYD_LINK(dst_net_elm->m_id, src_net_elm->m_id) =
 +               newExtendedRoute(p_hierarchy, route, 0);
 +      TO_FLOYD_PRED(dst_net_elm->m_id, src_net_elm->m_id) = dst_net_elm->m_id;
 +      TO_FLOYD_COST(dst_net_elm->m_id, src_net_elm->m_id) =
 +          ((TO_FLOYD_LINK(dst_net_elm->m_id, src_net_elm->m_id))->link_list)->used;   /* count of links, old model assume 1 */
      }
    }
    xbt_dynar_free(&route->link_list);
  }
 +
 +void AsFloyd::end(){
 +  unsigned int i, j, a, b, c;
 +
 +  /* set the size of table routing */
 +  size_t table_size = xbt_dynar_length(p_indexNetworkElm);
 +
 +  if(!p_linkTable) {
 +    /* Create Cost, Predecessor and Link tables */
 +    p_costTable = xbt_new0(double, table_size * table_size);       /* link cost from host to host */
 +    p_predecessorTable = xbt_new0(int, table_size * table_size);  /* predecessor host numbers */
 +    p_linkTable = xbt_new0(sg_platf_route_cbarg_t, table_size * table_size);    /* actual link between src and dst */
 +
 +    /* Initialize costs and predecessors */
 +    for (i = 0; i < table_size; i++)
 +      for (j = 0; j < table_size; j++) {
 +        TO_FLOYD_COST(i, j) = DBL_MAX;
 +        TO_FLOYD_PRED(i, j) = -1;
 +        TO_FLOYD_LINK(i, j) = NULL;       /* fixed, missing in the previous version */
 +      }
 +  }
 +
 +  /* Add the loopback if needed */
 +  if (routing_platf->p_loopback && p_hierarchy == SURF_ROUTING_BASE) {
 +    for (i = 0; i < table_size; i++) {
 +      sg_platf_route_cbarg_t e_route = TO_FLOYD_LINK(i, i);
 +      if (!e_route) {
 +        e_route = xbt_new0(s_sg_platf_route_cbarg_t, 1);
 +        e_route->gw_src = NULL;
 +        e_route->gw_dst = NULL;
 +        e_route->link_list = xbt_dynar_new(sizeof(sg_routing_link_t), NULL);
 +        xbt_dynar_push(e_route->link_list, &routing_platf->p_loopback);
 +        TO_FLOYD_LINK(i, i) = e_route;
 +        TO_FLOYD_PRED(i, i) = i;
 +        TO_FLOYD_COST(i, i) = 1;
 +      }
 +    }
 +  }
 +  /* Calculate path costs */
 +  for (c = 0; c < table_size; c++) {
 +    for (a = 0; a < table_size; a++) {
 +      for (b = 0; b < table_size; b++) {
 +        if (TO_FLOYD_COST(a, c) < DBL_MAX && TO_FLOYD_COST(c, b) < DBL_MAX) {
 +          if (TO_FLOYD_COST(a, b) == DBL_MAX ||
 +              (TO_FLOYD_COST(a, c) + TO_FLOYD_COST(c, b) <
 +                  TO_FLOYD_COST(a, b))) {
 +            TO_FLOYD_COST(a, b) =
 +                TO_FLOYD_COST(a, c) + TO_FLOYD_COST(c, b);
 +            TO_FLOYD_PRED(a, b) = TO_FLOYD_PRED(c, b);
 +          }
 +        }
 +      }
 +    }
 +  }
 +}
@@@ -1,86 -1,49 +1,92 @@@
+ /* Copyright (c) 2009-2013. 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. */
  #include "surf_routing_private.h"
 +#include "surf_routing_full.hpp"
 +#include "network.hpp"
 +
 +extern "C" {
 +XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_route_full, surf, "Routing part of surf");
 +}
  
  /* Global vars */
  extern routing_platf_t routing_platf;
  extern int surf_parse_lineno;
  
 -XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_route_full, surf, "Routing part of surf");
 +#define TO_ROUTE_FULL(i,j) p_routingTable[(i)+(j)*table_size]
  
 -#define TO_ROUTE_FULL(i,j) routing->routing_table[(i)+(j)*table_size]
 +AS_t model_full_create(void)
 +{
 +  return new AsFull();
 +}
  
 -/* Routing model structure */
 +void model_full_end(AS_t _routing)
 +{
 +  unsigned int i;
 +  sg_platf_route_cbarg_t e_route;
 +
 +  /* set utils vars */
 +  AsFullPtr routing = ((AsFullPtr) _routing);
 +  size_t table_size = xbt_dynar_length(routing->p_indexNetworkElm);
  
 -typedef struct s_routing_component_full {
 -  s_as_t generic_routing;
 -  sg_platf_route_cbarg_t *routing_table;
 -} s_routing_component_full_t, *routing_component_full_t;
 +  /* Create table if necessary */
 +  if (!routing->p_routingTable)
 +    routing->p_routingTable = xbt_new0(sg_platf_route_cbarg_t, table_size * table_size);
  
 -/* Business methods */
 -static xbt_dynar_t full_get_onelink_routes(AS_t rc)
 +  /* Add the loopback if needed */
 +  if (routing_platf->p_loopback && routing->p_hierarchy == SURF_ROUTING_BASE) {
 +    for (i = 0; i < table_size; i++) {
 +      e_route = routing->TO_ROUTE_FULL(i, i);
 +      if (!e_route) {
 +        e_route = xbt_new0(s_sg_platf_route_cbarg_t, 1);
 +        e_route->gw_src = NULL;
 +        e_route->gw_dst = NULL;
 +        e_route->link_list = xbt_dynar_new(sizeof(sg_routing_link_t), NULL);
 +        xbt_dynar_push(e_route->link_list, &routing_platf->p_loopback);
 +        routing->TO_ROUTE_FULL(i, i) = e_route;
 +      }
 +    }
 +  }
 +}
 +
 +AsFull::AsFull(){
 +  p_routingTable = 0;
 +}
 +
 +AsFull::~AsFull(){
 +  size_t table_size = xbt_dynar_length(p_indexNetworkElm);
 +  int i, j;
 +  /* Delete routing table */
 +  for (i = 0; i < table_size; i++)
 +    for (j = 0; j < table_size; j++)
 +      delete TO_ROUTE_FULL(i,j);
 +  xbt_free(p_routingTable);
 +}
 +
 +xbt_dynar_t AsFull::getOneLinkRoutes()
  {
    xbt_dynar_t ret = xbt_dynar_new(sizeof(onelink_t), xbt_free);
 -  routing_component_full_t routing = (routing_component_full_t) rc;
  
 -  int src,dst;
 -  int table_size = xbt_dynar_length(rc->index_network_elm);
 +  int src, dst;
 +  int table_size = xbt_dynar_length(p_indexNetworkElm);
  
    for(src=0; src < table_size; src++) {
      for(dst=0; dst< table_size; dst++) {
 -      sg_platf_route_cbarg_t route = TO_ROUTE_FULL(src, dst);
 +      sg_platf_route_cbarg_t route = TO_ROUTE_FULL(src,dst);
        if (route) {
          if (xbt_dynar_length(route->link_list) == 1) {
            void *link = *(void **) xbt_dynar_get_ptr(route->link_list, 0);
            onelink_t onelink = xbt_new0(s_onelink_t, 1);
            onelink->link_ptr = link;
 -          if (rc->hierarchy == SURF_ROUTING_BASE) {
 -            onelink->src = xbt_dynar_get_as(rc->index_network_elm,src,sg_routing_edge_t);
 -            onelink->src->id = src;
 -            onelink->dst = xbt_dynar_get_as(rc->index_network_elm,dst,sg_routing_edge_t);
 -            onelink->dst->id = dst;
 -          } else if (rc->hierarchy == SURF_ROUTING_RECURSIVE) {
 +          if (p_hierarchy == SURF_ROUTING_BASE) {
 +            onelink->src = xbt_dynar_get_as(p_indexNetworkElm, src, sg_routing_edge_t);
 +            onelink->src->m_id = src;
 +            onelink->dst = xbt_dynar_get_as(p_indexNetworkElm, dst, sg_routing_edge_t);
 +            onelink->dst->m_id = dst;
 +          } else if (p_hierarchy == SURF_ROUTING_RECURSIVE) {
              onelink->src = route->gw_src;
              onelink->dst = route->gw_dst;
            }
    return ret;
  }
  
 -static void full_get_route_and_latency(AS_t rc,
 -    sg_routing_edge_t src, sg_routing_edge_t dst,
 -    sg_platf_route_cbarg_t res, double *lat)
 +void AsFull::getRouteAndLatency(RoutingEdgePtr src, RoutingEdgePtr dst, sg_platf_route_cbarg_t res, double *lat)
  {
    XBT_DEBUG("full_get_route_and_latency from %s[%d] to %s[%d]",
 -      src->name,
 -      src->id,
 -      dst->name,
 -      dst->id  );
 +      src->p_name,
 +      src->m_id,
 +      dst->p_name,
 +      dst->m_id  );
  
    /* set utils vars */
 -  routing_component_full_t routing = (routing_component_full_t) rc;
 -  size_t table_size = xbt_dynar_length(routing->generic_routing.index_network_elm);
 +  size_t table_size = xbt_dynar_length(p_indexNetworkElm);
  
    sg_platf_route_cbarg_t e_route = NULL;
    void *link;
    unsigned int cpt = 0;
  
 -  e_route = TO_ROUTE_FULL(src->id, dst->id);
 +  e_route = TO_ROUTE_FULL(src->m_id, dst->m_id);
  
    if (e_route) {
      res->gw_src = e_route->gw_src;
      xbt_dynar_foreach(e_route->link_list, cpt, link) {
        xbt_dynar_push(res->link_list, &link);
        if (lat)
 -        *lat += surf_network_model->extension.network.get_link_latency(link);
 +        *lat += dynamic_cast<NetworkCm02LinkPtr>(static_cast<ResourcePtr>(link))->getLatency();
      }
    }
  }
  
 -static void full_finalize(AS_t rc)
 -{
 -  routing_component_full_t routing = (routing_component_full_t) rc;
 -  size_t table_size = xbt_dynar_length(routing->generic_routing.index_network_elm);
 -  int i, j;
 -  if (routing) {
 -    /* Delete routing table */
 -    for (i = 0; i < table_size; i++)
 -      for (j = 0; j < table_size; j++)
 -        generic_free_route(TO_ROUTE_FULL(i, j));
 -    xbt_free(routing->routing_table);
 -    model_generic_finalize(rc);
 -  }
 -}
 -
 -/* Creation routing model functions */
 -
 -AS_t model_full_create(void)
 -{
 -  routing_component_full_t new_component = (routing_component_full_t)
 -          model_generic_create_sized(sizeof(s_routing_component_full_t));
 -
 -  new_component->generic_routing.parse_route = model_full_set_route;
 -  new_component->generic_routing.parse_ASroute = model_full_set_route;
 -  new_component->generic_routing.get_route_and_latency =
 -      full_get_route_and_latency;
 -  new_component->generic_routing.get_graph = generic_get_graph;
 -
 -  new_component->generic_routing.get_onelink_routes = full_get_onelink_routes;
 -  new_component->generic_routing.finalize = full_finalize;
 -
 -  return (AS_t) new_component;
 -}
 -
 -void model_full_end(AS_t current_routing)
 -{
 -  unsigned int i;
 -  sg_platf_route_cbarg_t e_route;
 -
 -  /* set utils vars */
 -  routing_component_full_t routing =
 -      ((routing_component_full_t) current_routing);
 -  size_t table_size = xbt_dynar_length(routing->generic_routing.index_network_elm);
 -
 -  /* Create table if necessary */
 -  if (!routing->routing_table)
 -    routing->routing_table = xbt_new0(sg_platf_route_cbarg_t, table_size * table_size);
 -
 -  /* Add the loopback if needed */
 -  if (routing_platf->loopback && current_routing->hierarchy == SURF_ROUTING_BASE) {
 -    for (i = 0; i < table_size; i++) {
 -      e_route = TO_ROUTE_FULL(i, i);
 -      if (!e_route) {
 -        e_route = xbt_new0(s_sg_platf_route_cbarg_t, 1);
 -        e_route->gw_src = NULL;
 -        e_route->gw_dst = NULL;
 -        e_route->link_list = xbt_dynar_new(sizeof(sg_routing_link_t), NULL);
 -        xbt_dynar_push(e_route->link_list, &routing_platf->loopback);
 -        TO_ROUTE_FULL(i, i) = e_route;
 -      }
 -    }
 -  }
 +void AsFull::parseASroute(sg_platf_route_cbarg_t route){
 +  parseRoute(route);
  }
  
  static int full_pointer_resource_cmp(const void *a, const void *b)
    return a != b;
  }
  
 -void model_full_set_route(AS_t rc, sg_platf_route_cbarg_t route)
 +void AsFull::parseRoute(sg_platf_route_cbarg_t route)
  {
    int as_route = 0;
    char *src = (char*)(route->src);
    char *dst = (char*)(route->dst);
 -  sg_routing_edge_t src_net_elm, dst_net_elm;
 +  RoutingEdgePtr src_net_elm, dst_net_elm;
    src_net_elm = sg_routing_edge_by_name_or_null(src);
    dst_net_elm = sg_routing_edge_by_name_or_null(dst);
  
    xbt_assert(src_net_elm, "Network elements %s not found", src);
    xbt_assert(dst_net_elm, "Network elements %s not found", dst);
  
 -  routing_component_full_t routing = (routing_component_full_t) rc;
 -  size_t table_size = xbt_dynar_length(routing->generic_routing.index_network_elm);
 +  size_t table_size = xbt_dynar_length(p_indexNetworkElm);
  
    xbt_assert(!xbt_dynar_is_empty(route->link_list),
        "Invalid count of links, must be greater than zero (%s,%s)",
        src, dst);
  
 -  if (!routing->routing_table)
 -    routing->routing_table = xbt_new0(sg_platf_route_cbarg_t, table_size * table_size);
 +  if (!p_routingTable)
 +    p_routingTable = xbt_new0(sg_platf_route_cbarg_t, table_size * table_size);
  
 -  if (TO_ROUTE_FULL(src_net_elm->id, dst_net_elm->id)) {
 +  if (TO_ROUTE_FULL(src_net_elm->m_id, dst_net_elm->m_id)) {
      char *link_name;
      unsigned int i;
      xbt_dynar_t link_route_to_test =
        xbt_assert(link, "Link : '%s' doesn't exists.", link_name);
        xbt_dynar_push(link_route_to_test, &link);
      }
 -    if (xbt_dynar_compare(TO_ROUTE_FULL(src_net_elm->id, dst_net_elm->id)->link_list,
 +    if (xbt_dynar_compare(TO_ROUTE_FULL(src_net_elm->m_id, dst_net_elm->m_id)->link_list,
          link_route_to_test, full_pointer_resource_cmp)) {
        surf_parse_error("A route between \"%s\" and \"%s\" already exists "
            "with a different content. "
        //                         route->dst_gateway, subas->name);
        as_route = 1;
        XBT_DEBUG("Load ASroute from \"%s(%s)\" to \"%s(%s)\"",
 -          src, route->gw_src->name, dst, route->gw_dst->name);
 -      if (route->gw_dst->rc_type == SURF_NETWORK_ELEMENT_NULL)
 -        xbt_die("The dst_gateway '%s' does not exist!", route->gw_dst->name);
 -      if (route->gw_src->rc_type == SURF_NETWORK_ELEMENT_NULL)
 -        xbt_die("The src_gateway '%s' does not exist!", route->gw_src->name);
 +          src, route->gw_src->p_name, dst, route->gw_dst->p_name);
 +      if (route->gw_dst->p_rcType == SURF_NETWORK_ELEMENT_NULL)
 +        xbt_die("The dst_gateway '%s' does not exist!", route->gw_dst->p_name);
 +      if (route->gw_src->p_rcType == SURF_NETWORK_ELEMENT_NULL)
 +        xbt_die("The src_gateway '%s' does not exist!", route->gw_src->p_name);
      }
 -    TO_ROUTE_FULL(src_net_elm->id, dst_net_elm->id) =
 -        generic_new_extended_route(rc->hierarchy, route, 1);
 -    xbt_dynar_shrink(TO_ROUTE_FULL(src_net_elm->id, dst_net_elm->id)->link_list, 0);
 +    TO_ROUTE_FULL(src_net_elm->m_id, dst_net_elm->m_id) = newExtendedRoute(p_hierarchy, route, 1);
 +    xbt_dynar_shrink(TO_ROUTE_FULL(src_net_elm->m_id, dst_net_elm->m_id)->link_list, 0);
    }
  
    if ( (route->symmetrical == TRUE && as_route == 0)
        route->gw_src = route->gw_dst;
        route->gw_dst = gw_tmp;
      }
 -    if (TO_ROUTE_FULL(dst_net_elm->id, src_net_elm->id)) {
 +    if (TO_ROUTE_FULL(dst_net_elm->m_id, src_net_elm->m_id)) {
        char *link_name;
        unsigned int i;
        xbt_dynar_t link_route_to_test =
            xbt_dynar_new(sizeof(sg_routing_link_t), NULL);
        for (i = xbt_dynar_length(route->link_list); i > 0; i--) {
 -        link_name = xbt_dynar_get_as(route->link_list, i - 1, void *);
 +        link_name = xbt_dynar_get_as(route->link_list, i - 1, char *);
          void *link = xbt_lib_get_or_null(link_lib, link_name, SURF_LINK_LEVEL);
          xbt_assert(link, "Link : '%s' doesn't exists.", link_name);
          xbt_dynar_push(link_route_to_test, &link);
        }
 -      xbt_assert(!xbt_dynar_compare(TO_ROUTE_FULL(dst_net_elm->id, src_net_elm->id)->link_list,
 +      xbt_assert(!xbt_dynar_compare(TO_ROUTE_FULL(dst_net_elm->m_id, src_net_elm->m_id)->link_list,
            link_route_to_test,
            full_pointer_resource_cmp),
            "The route between \"%s\" and \"%s\" already exists", src,
          XBT_DEBUG("Load Route from \"%s\" to \"%s\"", dst, src);
        else
          XBT_DEBUG("Load ASroute from \"%s(%s)\" to \"%s(%s)\"",
 -            dst, route->gw_src->name, src, route->gw_dst->name);
 -      TO_ROUTE_FULL(dst_net_elm->id, src_net_elm->id) =
 -          generic_new_extended_route(rc->hierarchy, route, 0);
 -      xbt_dynar_shrink(TO_ROUTE_FULL(dst_net_elm->id, src_net_elm->id)->link_list, 0);
 +            dst, route->gw_src->p_name, src, route->gw_dst->p_name);
 +      TO_ROUTE_FULL(dst_net_elm->m_id, src_net_elm->m_id) = newExtendedRoute(p_hierarchy, route, 0);
 +      xbt_dynar_shrink(TO_ROUTE_FULL(dst_net_elm->m_id, src_net_elm->m_id)->link_list, 0);
      }
    }
    xbt_dynar_free(&route->link_list);
  }
 +
 +
 +
 +
@@@ -1,4 -1,4 +1,4 @@@
- /* Copyright (c) 2009, 2010, 2011. The SimGrid Team.
+ /* Copyright (c) 2009-2013. The SimGrid Team.
   * All rights reserved.                                                     */
  
  /* This program is free software; you can redistribute it and/or modify it
@@@ -6,59 -6,52 +6,59 @@@
  
  #include "simgrid/platf_interface.h"    // platform creation API internal interface
  
 -#include "surf_routing_private.h"
 -#include "surf/surf_routing.h"
 -#include "surf/surfxml_parse_values.h"
 +#include "surf_routing_generic.hpp"
 +#include "network.hpp"
  #include "xbt/graph.h"
  
 +extern "C" {
  XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_routing_generic, surf_route, "Generic implementation of the surf routing");
 +}
  
  static int no_bypassroute_declared = 1;
  
 -AS_t model_generic_create_sized(size_t childsize) {
 -  AS_t new_component = model_none_create_sized(childsize);
 -
 -  new_component->parse_PU = generic_parse_PU;
 -  new_component->parse_AS = generic_parse_AS;
 -  new_component->parse_route = NULL;
 -  new_component->parse_ASroute = NULL;
 -  new_component->parse_bypassroute = generic_parse_bypassroute;
 -  new_component->get_route_and_latency = NULL;
 -  new_component->get_onelink_routes = NULL;
 -  new_component->get_bypass_route =
 -      generic_get_bypassroute;
 -  new_component->finalize = model_generic_finalize;
 -  new_component->bypassRoutes = xbt_dict_new_homogeneous((void (*)(void *)) generic_free_route);
 -
 -  return new_component;
 +void generic_free_route(sg_platf_route_cbarg_t route)
 +{
 +  if (route) {
 +    xbt_dynar_free(&route->link_list);
 +    xbt_free(route);
 +  }
 +}
 +
 +void AsGeneric::parseRoute(sg_platf_route_cbarg_t route){
 +  THROW_IMPOSSIBLE;
 +}
 +
 +void AsGeneric::parseASroute(sg_platf_route_cbarg_t route){
 +  THROW_IMPOSSIBLE;
 +}
 +
 +void AsGeneric::getRouteAndLatency(RoutingEdgePtr src, RoutingEdgePtr dst, sg_platf_route_cbarg_t into, double *latency){
 +  THROW_IMPOSSIBLE;
 +}
 +
 +AsGeneric::AsGeneric() {
 +  p_bypassRoutes = xbt_dict_new_homogeneous((void (*)(void *)) generic_free_route);
  }
 -void model_generic_finalize(AS_t as) {
 -  xbt_dict_free(&as->bypassRoutes);
 -  model_none_finalize(as);
 +
 +AsGeneric::~AsGeneric() {
 +  xbt_dict_free(&p_bypassRoutes);
  }
  
 -int generic_parse_PU(AS_t as, sg_routing_edge_t elm)
 +int AsGeneric::parsePU(RoutingEdgePtr elm)
  {
 -  XBT_DEBUG("Load process unit \"%s\"", elm->name);
 -  xbt_dynar_push_as(as->index_network_elm,sg_routing_edge_t,elm);
 -  return xbt_dynar_length(as->index_network_elm)-1;
 +  XBT_DEBUG("Load process unit \"%s\"", elm->p_name);
 +  xbt_dynar_push_as(p_indexNetworkElm, RoutingEdgePtr, elm);
 +  return xbt_dynar_length(p_indexNetworkElm)-1;
  }
  
 -int generic_parse_AS(AS_t as, sg_routing_edge_t elm)
 +int AsGeneric::parseAS(RoutingEdgePtr elm)
  {
 -  XBT_DEBUG("Load Autonomous system \"%s\"", elm->name);
 -  xbt_dynar_push_as(as->index_network_elm,sg_routing_edge_t,elm);
 -  return xbt_dynar_length(as->index_network_elm)-1;
 +  XBT_DEBUG("Load Autonomous system \"%s\"", elm->p_name);
 +  xbt_dynar_push_as(p_indexNetworkElm, RoutingEdgePtr, elm);
 +  return xbt_dynar_length(p_indexNetworkElm)-1;
  }
  
 -void generic_parse_bypassroute(AS_t rc, sg_platf_route_cbarg_t e_route)
 +void AsGeneric::parseBypassroute(sg_platf_route_cbarg_t e_route)
  {
    char *src = (char*)(e_route->src);
    char *dst = (char*)(e_route->dst);
@@@ -67,7 -60,7 +67,7 @@@
      XBT_DEBUG("Load bypassASroute from \"%s\" to \"%s\"", src, dst);
    else
      XBT_DEBUG("Load bypassRoute from \"%s\" to \"%s\"", src, dst);
 -  xbt_dict_t dict_bypassRoutes = rc->bypassRoutes;
 +  xbt_dict_t dict_bypassRoutes = p_bypassRoutes;
    char *route_name;
  
    route_name = bprintf("%s#%s", src, dst);
        src, dst);
    xbt_assert(!xbt_dict_get_or_null(dict_bypassRoutes, route_name),
        "The bypass route between \"%s\"(\"%s\") and \"%s\"(\"%s\") already exists",
 -      src, e_route->gw_src->name, dst, e_route->gw_dst->name);
 +      src, e_route->gw_src->p_name, dst, e_route->gw_dst->p_name);
  
    sg_platf_route_cbarg_t new_e_route = NULL;
    if(e_route->gw_dst)
 -    new_e_route =  generic_new_extended_route(SURF_ROUTING_RECURSIVE, e_route, 1);
 +    new_e_route =  newExtendedRoute(SURF_ROUTING_RECURSIVE, e_route, 1);
    else
 -    new_e_route =  generic_new_extended_route(SURF_ROUTING_BASE, e_route, 1);
 +    new_e_route =  newExtendedRoute(SURF_ROUTING_BASE, e_route, 1);
  
    xbt_dynar_free(&(e_route->link_list));
  
@@@ -94,7 -87,7 +94,7 @@@
  /* ************************************************************************** */
  /* *********************** GENERIC BUSINESS METHODS ************************* */
  
 -xbt_dynar_t generic_get_onelink_routes(AS_t rc) { // FIXME: kill that stub
 +xbt_dynar_t AsGeneric::getOneLinkRoutes() { // FIXME: kill that stub
    xbt_die("\"generic_get_onelink_routes\" not implemented yet");
    return NULL;
  }
@@@ -109,7 -102,7 +109,7 @@@ static const char *instr_node_name(xbt_
  xbt_node_t new_xbt_graph_node(xbt_graph_t graph, const char *name,
                                xbt_dict_t nodes)
  {
 -  xbt_node_t ret = xbt_dict_get_or_null(nodes, name);
 +  xbt_node_t ret = (xbt_node_t) xbt_dict_get_or_null(nodes, name);
    if (ret)
      return ret;
  
@@@ -130,10 -123,10 +130,10 @@@ xbt_edge_t new_xbt_graph_edge(xbt_graph
  
  
    snprintf(name, len, "%s%s", sn, dn);
 -  ret = xbt_dict_get_or_null(edges, name);
 +  ret = (xbt_edge_t) xbt_dict_get_or_null(edges, name);
    if (ret == NULL) {
      snprintf(name, len, "%s%s", dn, sn);
 -    ret = xbt_dict_get_or_null(edges, name);
 +    ret = (xbt_edge_t) xbt_dict_get_or_null(edges, name);
    }
  
    if (ret == NULL) {
    return ret;
  }
  
 -void generic_get_graph(xbt_graph_t graph, xbt_dict_t nodes, xbt_dict_t edges,
 -                       AS_t rc)
 +void AsGeneric::getGraph(xbt_graph_t graph, xbt_dict_t nodes, xbt_dict_t edges)
  {
    int src, dst;
 -  int table_size = xbt_dynar_length(rc->index_network_elm);
 +  int table_size = xbt_dynar_length(p_indexNetworkElm);
  
  
    for (src = 0; src < table_size; src++) {
 -    sg_routing_edge_t my_src =
 -        xbt_dynar_get_as(rc->index_network_elm, src, sg_routing_edge_t);
 +    RoutingEdgePtr my_src =
 +        xbt_dynar_get_as(p_indexNetworkElm, src, RoutingEdgePtr);
      for (dst = 0; dst < table_size; dst++) {
        if (src == dst)
          continue;
 -      sg_routing_edge_t my_dst =
 -          xbt_dynar_get_as(rc->index_network_elm, dst, sg_routing_edge_t);
 +      RoutingEdgePtr my_dst =
 +          xbt_dynar_get_as(p_indexNetworkElm, dst, RoutingEdgePtr);
  
        sg_platf_route_cbarg_t route = xbt_new0(s_sg_platf_route_cbarg_t, 1);
        route->link_list = xbt_dynar_new(sizeof(sg_routing_link_t), NULL);
  
 -      rc->get_route_and_latency(rc, my_src, my_dst, route, NULL);
 +      getRouteAndLatency(my_src, my_dst, route, NULL);
  
 -      XBT_DEBUG ("get_route_and_latency %s -> %s", my_src->name, my_dst->name);
 +      XBT_DEBUG ("get_route_and_latency %s -> %s", my_src->p_name, my_dst->p_name);
  
        unsigned int cpt;
        void *link;
        const char *previous_name, *current_name;
  
        if (route->gw_src) {
 -        previous = new_xbt_graph_node(graph, route->gw_src->name, nodes);
 -        previous_name = route->gw_src->name;
 +        previous = new_xbt_graph_node(graph, route->gw_src->p_name, nodes);
 +        previous_name = route->gw_src->p_name;
        } else {
 -        previous = new_xbt_graph_node(graph, my_src->name, nodes);
 -        previous_name = my_src->name;
 +        previous = new_xbt_graph_node(graph, my_src->p_name, nodes);
 +        previous_name = my_src->p_name;
        }
  
        xbt_dynar_foreach(route->link_list, cpt, link) {
 -        char *link_name = ((surf_resource_t) link)->name;
 +        const char *link_name = ((ResourcePtr) link)->m_name;
          current = new_xbt_graph_node(graph, link_name, nodes);
          current_name = link_name;
          new_xbt_graph_edge(graph, previous, current, edges);
        }
  
        if (route->gw_dst) {
 -        current = new_xbt_graph_node(graph, route->gw_dst->name, nodes);
 -        current_name = route->gw_dst->name;
 +        current = new_xbt_graph_node(graph, route->gw_dst->p_name, nodes);
 +        current_name = route->gw_dst->p_name;
        } else {
 -        current = new_xbt_graph_node(graph, my_dst->name, nodes);
 -        current_name = my_dst->name;
 +        current = new_xbt_graph_node(graph, my_dst->p_name, nodes);
 +        current_name = my_dst->p_name;
        }
        new_xbt_graph_edge(graph, previous, current, edges);
        XBT_DEBUG ("  %s -> %s", previous_name, current_name);
    }
  }
  
 -sg_platf_route_cbarg_t generic_get_bypassroute(AS_t rc, sg_routing_edge_t src,
 -                                               sg_routing_edge_t dst,
 +sg_platf_route_cbarg_t AsGeneric::getBypassRoute(RoutingEdgePtr src,
 +                                               RoutingEdgePtr dst,
                                                 double *lat)
  {
    // If never set a bypass route return NULL without any further computations
 -  XBT_DEBUG("generic_get_bypassroute from %s to %s", src->name, dst->name);
 +  XBT_DEBUG("generic_get_bypassroute from %s to %s", src->p_name, dst->p_name);
    if (no_bypassroute_declared)
      return NULL;
  
    sg_platf_route_cbarg_t e_route_bypass = NULL;
 -  xbt_dict_t dict_bypassRoutes = rc->bypassRoutes;
 +  xbt_dict_t dict_bypassRoutes = p_bypassRoutes;
  
 -  if(dst->rc_component == rc && src->rc_component == rc ){
 -    char *route_name = bprintf("%s#%s", src->name, dst->name);
 -    e_route_bypass = xbt_dict_get_or_null(dict_bypassRoutes, route_name);
 +  if(dst->p_rcComponent == this && src->p_rcComponent == this ){
 +    char *route_name = bprintf("%s#%s", src->p_name, dst->p_name);
 +    e_route_bypass = (sg_platf_route_cbarg_t) xbt_dict_get_or_null(dict_bypassRoutes, route_name);
      if(e_route_bypass)
        XBT_DEBUG("Find bypass route with %ld links",xbt_dynar_length(e_route_bypass->link_list));
      free(route_name);
    }
    else{
 -    AS_t src_as, dst_as;
 +    AsPtr src_as, dst_as;
      int index_src, index_dst;
      xbt_dynar_t path_src = NULL;
      xbt_dynar_t path_dst = NULL;
 -    AS_t current = NULL;
 -    AS_t *current_src = NULL;
 -    AS_t *current_dst = NULL;
 +    AsPtr current = NULL;
 +    AsPtr *current_src = NULL;
 +    AsPtr *current_dst = NULL;
  
      if (src == NULL || dst == NULL)
        xbt_die("Ask for route \"from\"(%s) or \"to\"(%s) no found at AS \"%s\"",
 -          src->name, dst->name, rc->name);
 +          src->p_name, dst->p_name, p_name);
  
 -    src_as = src->rc_component;
 -    dst_as = dst->rc_component;
 +    src_as = src->p_rcComponent;
 +    dst_as = dst->p_rcComponent;
  
      /* (2) find the path to the root routing component */
 -    path_src = xbt_dynar_new(sizeof(AS_t), NULL);
 +    path_src = xbt_dynar_new(sizeof(AsPtr), NULL);
      current = src_as;
      while (current != NULL) {
        xbt_dynar_push(path_src, &current);
 -      current = current->routing_father;
 +      current = current->p_routingFather;
      }
 -    path_dst = xbt_dynar_new(sizeof(AS_t), NULL);
 +    path_dst = xbt_dynar_new(sizeof(AsPtr), NULL);
      current = dst_as;
      while (current != NULL) {
        xbt_dynar_push(path_dst, &current);
 -      current = current->routing_father;
 +      current = current->p_routingFather;
      }
  
      /* (3) find the common father */
      index_src = path_src->used - 1;
      index_dst = path_dst->used - 1;
 -    current_src = xbt_dynar_get_ptr(path_src, index_src);
 -    current_dst = xbt_dynar_get_ptr(path_dst, index_dst);
 +    current_src = (AsPtr *) xbt_dynar_get_ptr(path_src, index_src);
 +    current_dst = (AsPtr *) xbt_dynar_get_ptr(path_dst, index_dst);
      while (index_src >= 0 && index_dst >= 0 && *current_src == *current_dst) {
        xbt_dynar_pop_ptr(path_src);
        xbt_dynar_pop_ptr(path_dst);
        index_src--;
        index_dst--;
 -      current_src = xbt_dynar_get_ptr(path_src, index_src);
 -      current_dst = xbt_dynar_get_ptr(path_dst, index_dst);
 +      current_src = (AsPtr *) xbt_dynar_get_ptr(path_src, index_src);
 +      current_dst = (AsPtr *) xbt_dynar_get_ptr(path_dst, index_dst);
      }
  
      int max_index_src = path_src->used - 1;
        for (i = 0; i < max; i++) {
          if (i <= max_index_src && max <= max_index_dst) {
            char *route_name = bprintf("%s#%s",
 -              (*(AS_t *)
 -                  (xbt_dynar_get_ptr(path_src, i)))->name,
 -                  (*(AS_t *)
 -                      (xbt_dynar_get_ptr(path_dst, max)))->name);
 -          e_route_bypass = xbt_dict_get_or_null(dict_bypassRoutes, route_name);
 +              (*(AsPtr *)
 +                  (xbt_dynar_get_ptr(path_src, i)))->p_name,
 +                  (*(AsPtr *)
 +                      (xbt_dynar_get_ptr(path_dst, max)))->p_name);
 +          e_route_bypass = (sg_platf_route_cbarg_t) xbt_dict_get_or_null(dict_bypassRoutes, route_name);
            xbt_free(route_name);
          }
          if (e_route_bypass)
            break;
          if (max <= max_index_src && i <= max_index_dst) {
            char *route_name = bprintf("%s#%s",
 -              (*(AS_t *)
 -                  (xbt_dynar_get_ptr(path_src, max)))->name,
 -                  (*(AS_t *)
 -                      (xbt_dynar_get_ptr(path_dst, i)))->name);
 -          e_route_bypass = xbt_dict_get_or_null(dict_bypassRoutes, route_name);
 +              (*(AsPtr *)
 +                  (xbt_dynar_get_ptr(path_src, max)))->p_name,
 +                  (*(AsPtr *)
 +                      (xbt_dynar_get_ptr(path_dst, i)))->p_name);
 +          e_route_bypass = (sg_platf_route_cbarg_t) xbt_dict_get_or_null(dict_bypassRoutes, route_name);
            xbt_free(route_name);
          }
          if (e_route_bypass)
  
        if (max <= max_index_src && max <= max_index_dst) {
          char *route_name = bprintf("%s#%s",
 -            (*(AS_t *)
 -                (xbt_dynar_get_ptr(path_src, max)))->name,
 -                (*(AS_t *)
 -                    (xbt_dynar_get_ptr(path_dst, max)))->name);
 -        e_route_bypass = xbt_dict_get_or_null(dict_bypassRoutes, route_name);
 +            (*(AsPtr *)
 +                (xbt_dynar_get_ptr(path_src, max)))->p_name,
 +                (*(AsPtr *)
 +                    (xbt_dynar_get_ptr(path_dst, max)))->p_name);
 +        e_route_bypass = (sg_platf_route_cbarg_t) xbt_dict_get_or_null(dict_bypassRoutes, route_name);
          xbt_free(route_name);
        }
        if (e_route_bypass)
  
    sg_platf_route_cbarg_t new_e_route = NULL;
    if (e_route_bypass) {
 -    void *link;
 +    NetworkCm02LinkPtr link;
      unsigned int cpt = 0;
      new_e_route = xbt_new0(s_sg_platf_route_cbarg_t, 1);
      new_e_route->gw_src = e_route_bypass->gw_src;
      xbt_dynar_foreach(e_route_bypass->link_list, cpt, link) {
        xbt_dynar_push(new_e_route->link_list, &link);
        if (lat)
 -        *lat += surf_network_model->extension.network.get_link_latency(link);
 +        *lat += link->getLatency();
      }
    }
  
  /* ************************************************************************** */
  /* ************************* GENERIC AUX FUNCTIONS ************************** */
  /* change a route containing link names into a route containing link entities */
 -sg_platf_route_cbarg_t
 -generic_new_extended_route(e_surf_routing_hierarchy_t hierarchy,
 -    sg_platf_route_cbarg_t routearg, int change_order) {
 +sg_platf_route_cbarg_t AsGeneric::newExtendedRoute(e_surf_routing_hierarchy_t hierarchy,
 +      sg_platf_route_cbarg_t routearg, int change_order) {
  
    sg_platf_route_cbarg_t result;
    char *link_name;
    return result;
  }
  
 -void generic_free_route(sg_platf_route_cbarg_t route)
 -{
 -  if (route) {
 -    xbt_dynar_free(&route->link_list);
 -    xbt_free(route);
 -  }
 -}
  
 -static AS_t generic_as_exist(AS_t find_from,
 -    AS_t to_find)
 +
 +AsPtr AsGeneric::asExist(AsPtr to_find)
  {
    //return to_find; // FIXME: BYPASSERROR OF FOREACH WITH BREAK
    xbt_dict_cursor_t cursor = NULL;
    char *key;
    int found = 0;
 -  AS_t elem;
 -  xbt_dict_foreach(find_from->routing_sons, cursor, key, elem) {
 -    if (to_find == elem || generic_as_exist(elem, to_find)) {
 +  AsGenericPtr elem;
 +  xbt_dict_foreach(p_routingSons, cursor, key, elem) {
 +    if (to_find == elem || elem->asExist(to_find)) {
        found = 1;
        break;
      }
    return NULL;
  }
  
 -AS_t
 -generic_autonomous_system_exist(AS_t rc, char *element)
 +AsPtr AsGeneric::autonomousSystemExist(char *element)
  {
    //return rc; // FIXME: BYPASSERROR OF FOREACH WITH BREAK
 -  AS_t element_as, result, elem;
 +  AsPtr element_as, result, elem;
    xbt_dict_cursor_t cursor = NULL;
    char *key;
 -  element_as = ((sg_routing_edge_t)
 +  element_as = ((RoutingEdgePtr)
        xbt_lib_get_or_null(as_router_lib, element,
 -          ROUTING_ASR_LEVEL))->rc_component;
 -  result = ((AS_t) - 1);
 -  if (element_as != rc)
 -    result = generic_as_exist(rc, element_as);
 +          ROUTING_ASR_LEVEL))->p_rcComponent;
 +  result = ((AsPtr) - 1);
 +  if (element_as != this)
 +    result = asExist(element_as);
  
    int found = 0;
    if (result) {
 -    xbt_dict_foreach(element_as->routing_sons, cursor, key, elem) {
 -      found = !strcmp(elem->name, element);
 +    xbt_dict_foreach(element_as->p_routingSons, cursor, key, elem) {
 +      found = !strcmp(elem->p_name, element);
        if (found)
          break;
      }
    return NULL;
  }
  
 -AS_t
 -generic_processing_units_exist(AS_t rc, char *element)
 +AsPtr AsGeneric::processingUnitsExist(char *element)
  {
 -  AS_t element_as;
 -  element_as = ((sg_routing_edge_t)
 +  AsPtr element_as;
 +  element_as = ((RoutingEdgePtr)
        xbt_lib_get_or_null(host_lib,
 -          element, ROUTING_HOST_LEVEL))->rc_component;
 -  if (element_as == rc)
 +          element, ROUTING_HOST_LEVEL))->p_rcComponent;
 +  if (element_as == this)
      return element_as;
 -  return generic_as_exist(rc, element_as);
 +  return asExist(element_as);
  }
  
 -void generic_src_dst_check(AS_t rc, sg_routing_edge_t src,
 -    sg_routing_edge_t dst)
 +void AsGeneric::srcDstCheck(RoutingEdgePtr src, RoutingEdgePtr dst)
  {
  
 -  sg_routing_edge_t src_data = src;
 -  sg_routing_edge_t dst_data = dst;
 +  RoutingEdgePtr src_data = src;
 +  RoutingEdgePtr dst_data = dst;
  
    if (src_data == NULL || dst_data == NULL)
      xbt_die("Ask for route \"from\"(%s) or \"to\"(%s) no found at AS \"%s\"",
 -        src->name,
 -        dst->name,
 -        rc->name);
 +        src->p_name,
 +        dst->p_name,
 +        p_name);
  
 -  AS_t src_as =
 -      (src_data)->rc_component;
 -  AS_t dst_as =
 -      (dst_data)->rc_component;
 +  AsPtr src_as =
 +      (src_data)->p_rcComponent;
 +  AsPtr dst_as =
 +      (dst_data)->p_rcComponent;
  
    if (src_as != dst_as)
      xbt_die("The src(%s in %s) and dst(%s in %s) are in differents AS",
 -        src->name, src_as->name,
 -        dst->name, dst_as->name);
 +        src->p_name, src_as->p_name,
 +        dst->p_name, dst_as->p_name);
  
 -  if (rc != dst_as)
 +  if (this != dst_as)
      xbt_die
      ("The routing component of src'%s' and dst'%s' is not the same as the network elements belong (%s?=%s?=%s)",
 -        src->name,
 -        dst->name,
 -        src_as->name,
 -        dst_as->name,
 -        rc->name);
 +        src->p_name,
 +        dst->p_name,
 +        src_as->p_name,
 +        dst_as->p_name,
 +        p_name);
  }
@@@ -1,4 -1,4 +1,4 @@@
- /* Copyright (c) 2009, 2010, 2011. The SimGrid Team.
+ /* Copyright (c) 2009-2013. The SimGrid Team.
   * All rights reserved.                                                     */
  
  /* This program is free software; you can redistribute it and/or modify it
  #include <float.h>
  #include "internal_config.h"
  
 -#include "surf_private.h"
 +//#include "surf_private.h"
  #include "xbt/dynar.h"
  #include "xbt/str.h"
  #include "xbt/config.h"
  #include "xbt/graph.h"
  #include "xbt/set.h"
  #include "surf/surfxml_parse.h"
 +#include "surf_routing.hpp"
  
  /* ************************************************************************** */
  /* ******************************* NO ROUTING ******************************* */
  /* Only save the AS tree, and forward calls to child ASes */
 -AS_t model_none_create(void);
 -AS_t model_none_create_sized(size_t childsize);
 -void model_none_finalize(AS_t as);
 +AsPtr model_none_create(void);
 +AsPtr model_none_create_sized(size_t childsize);
 +void model_none_finalize(AsPtr as);
  /* ************************************************************************** */
  /* ***************** GENERIC PARSE FUNCTIONS (declarations) ***************** */
 -AS_t model_generic_create_sized(size_t childsize);
 -void model_generic_finalize(AS_t as);
 +AsPtr model_generic_create_sized(size_t childsize);
 +void model_generic_finalize(AsPtr as);
  
 -int generic_parse_PU(AS_t rc, sg_routing_edge_t elm);
 -int generic_parse_AS(AS_t rc, sg_routing_edge_t elm);
 -void generic_parse_bypassroute(AS_t rc, sg_platf_route_cbarg_t e_route);
 +int generic_parse_PU(AsPtr rc, RoutingEdgePtr elm);
 +int generic_parse_AS(AsPtr rc, RoutingEdgePtr elm);
 +void generic_parse_bypassroute(AsPtr rc, sg_platf_route_cbarg_t e_route);
  
  /* ************************************************************************** */
  /* *************** GENERIC BUSINESS METHODS (declarations) ****************** */
  
 -xbt_dynar_t generic_get_onelink_routes(AS_t rc);
 -sg_platf_route_cbarg_t generic_get_bypassroute(AS_t rc,
 -    sg_routing_edge_t src,
 -    sg_routing_edge_t dst,
 +xbt_dynar_t generic_get_onelink_routes(AsPtr rc);
 +sg_platf_route_cbarg_t generic_get_bypassroute(AsPtr rc,
 +    RoutingEdgePtr src,
 +    RoutingEdgePtr dst,
      double *lat);
  
  /* ************************************************************************** */
   * produced route */
  sg_platf_route_cbarg_t generic_new_extended_route(e_surf_routing_hierarchy_t hierarchy,
                                     sg_platf_route_cbarg_t data, int preserve_order);
 -AS_t
 -generic_autonomous_system_exist(AS_t rc, char *element);
 -AS_t
 -generic_processing_units_exist(AS_t rc, char *element);
 -void generic_src_dst_check(AS_t rc, sg_routing_edge_t src,
 -    sg_routing_edge_t dst);
 +AsPtr
 +generic_autonomous_system_exist(AsPtr rc, char *element);
 +AsPtr
 +generic_processing_units_exist(AsPtr rc, char *element);
 +void generic_src_dst_check(AsPtr rc, RoutingEdgePtr src,
 +    RoutingEdgePtr dst);
  
  /* ************************************************************************** */
  /* *************************** FLOYD ROUTING ******************************** */
 -AS_t model_floyd_create(void);  /* create structures for floyd routing model */
 -void model_floyd_end(AS_t as);      /* finalize the creation of floyd routing model */
 -void model_floyd_parse_route(AS_t rc, sg_platf_route_cbarg_t route);
 +AsPtr model_floyd_create(void);  /* create structures for floyd routing model */
 +void model_floyd_end(AsPtr as);      /* finalize the creation of floyd routing model */
 +void model_floyd_parse_route(AsPtr rc, sg_platf_route_cbarg_t route);
  
 -/* ************************************************** */
 -/* **************  Cluster ROUTING   **************** */
 -typedef struct {
 -  s_as_t generic_routing;
 -  void *backbone;
 -  void *loopback;
 -  sg_routing_edge_t router;
 -} s_as_cluster_t, *as_cluster_t;
 -
 -AS_t model_cluster_create(void);      /* create structures for cluster routing model */
 +AsPtr model_cluster_create(void);      /* create structures for cluster routing model */
  
  /* ************************************************** */
  /* **************  Vivaldi ROUTING   **************** */
 -AS_t model_vivaldi_create(void);      /* create structures for vivaldi routing model */
 +AsPtr model_vivaldi_create(void);      /* create structures for vivaldi routing model */
  #define HOST_PEER(peername) bprintf("peer_%s", peername)
  #define ROUTER_PEER(peername) bprintf("router_%s", peername)
  #define LINK_PEER(peername) bprintf("link_%s", peername)
  
  /* ************************************************************************** */
  /* ********** Dijkstra & Dijkstra Cached ROUTING **************************** */
 -AS_t model_dijkstra_both_create(int cached);    /* create by calling dijkstra or dijkstracache */
 -AS_t model_dijkstra_create(void);       /* create structures for dijkstra routing model */
 -AS_t model_dijkstracache_create(void);  /* create structures for dijkstracache routing model */
 -void model_dijkstra_both_end(AS_t as);      /* finalize the creation of dijkstra routing model */
 -void model_dijkstra_both_parse_route (AS_t rc, sg_platf_route_cbarg_t route);
 +AsPtr model_dijkstra_both_create(int cached);    /* create by calling dijkstra or dijkstracache */
 +AsPtr model_dijkstra_create(void);       /* create structures for dijkstra routing model */
 +AsPtr model_dijkstracache_create(void);  /* create structures for dijkstracache routing model */
 +void model_dijkstra_both_end(AsPtr as);      /* finalize the creation of dijkstra routing model */
 +void model_dijkstra_both_parse_route (AsPtr rc, sg_platf_route_cbarg_t route);
  
  /* ************************************************************************** */
  /* *************************** FULL ROUTING ********************************* */
 -AS_t model_full_create(void);   /* create structures for full routing model */
 -void model_full_end(AS_t as);       /* finalize the creation of full routing model */
 +AsPtr model_full_create(void);   /* create structures for full routing model */
 +void model_full_end(AsPtr as);       /* finalize the creation of full routing model */
  void model_full_set_route(  /* Set the route and ASroute between src and dst */
 -    AS_t rc, sg_platf_route_cbarg_t route);
 +    AsPtr rc, sg_platf_route_cbarg_t route);
  /* ************************************************************************** */
  /* ************************* GRAPH EXPORTING FUNCTIONS ********************** */
  xbt_node_t new_xbt_graph_node (xbt_graph_t graph, const char *name, xbt_dict_t nodes);
diff --combined src/surf/surfxml_parse.c
@@@ -1,4 -1,4 +1,4 @@@
- /* Copyright (c) 2006, 2007, 2008, 2009, 2010, 2011. The SimGrid Team.
+ /* Copyright (c) 2006-2013. The SimGrid Team.
   * All rights reserved.                                                     */
  
  /* This program is free software; you can redistribute it and/or modify it
@@@ -14,7 -14,6 +14,7 @@@
  #include "xbt/dict.h"
  #include "surf/surfxml_parse.h"
  #include "surf/surf_private.h"
 +#include "surf/random_mgr.h"
  #include "simgrid/sg_config.h"
  
  XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_parse, surf,
@@@ -34,9 -33,12 +34,12 @@@ extern AS_t current_routing
  void surf_parse_error(const char *fmt, ...) {
    va_list va;
    va_start(va,fmt);
+   int lineno = surf_parse_lineno;
    char *msg = bvprintf(fmt,va);
    va_end(va);
-   xbt_die("Parse error at %s:%d: %s", surf_parsed_filename, surf_parse_lineno, msg);
+   cleanup();
+   surf_exit();
+   xbt_die("Parse error at %s:%d: %s", surf_parsed_filename, lineno, msg);
  }
  void surf_parse_warn(const char *fmt, ...) {
    va_list va;
@@@ -52,7 -54,7 +55,7 @@@ double surf_parse_get_double(const cha
    int ret = sscanf(string, "%lg", &res);
    if (ret != 1)
      surf_parse_error("%s is not a double", string);
-   //printf("Parsed double [%lg] %s\n", res, string);  
+   //printf("Parsed double [%g] %s\n", res, string);
    return res;
  }
  
@@@ -110,6 -112,33 +113,33 @@@ double surf_parse_get_time(const char *
    return surf_parse_get_value_with_unit(string, units);
  }
  
+ double surf_parse_get_size(const char *string)
+ {
+   const struct unit_scale units[] = {
+     { "TiB", pow(1024, 4) },
+     { "GiB", pow(1024, 3) },
+     { "MiB", pow(1024, 2) },
+     { "KiB", 1024 },
+     { "TB",  1e12 },
+     { "GB",  1e9 },
+     { "MB",  1e6 },
+     { "kB",  1e3 },
+     { "B",   1.0 },
+     { "",      1.0 },           /* default unit is bytes*/
+     { "Tib", 0.125 * pow(1024, 4) },
+     { "Gib", 0.125 * pow(1024, 3) },
+     { "Mib", 0.125 * pow(1024, 2) },
+     { "Kib", 0.125 * 1024 },
+     { "Tb",  0.125 * 1e12 },
+     { "Gb",  0.125 * 1e9 },
+     { "Mb",  0.125 * 1e6 },
+     { "kb",  0.125 * 1e3 },
+     { "b",   0.125 },
+     { NULL,    0 }
+   };
+   return surf_parse_get_value_with_unit(string, units);
+ }
  double surf_parse_get_bandwidth(const char *string)
  {
    const struct unit_scale units[] = {
@@@ -206,6 -235,7 +236,7 @@@ void ETag_surfxml_storage(void
    storage.id = A_surfxml_storage_id;
    storage.type_id = A_surfxml_storage_typeId;
    storage.content = A_surfxml_storage_content;
+   storage.content_type = A_surfxml_storage_content___type;
    storage.properties = current_property_set;
    sg_platf_new_storage(&storage);
    current_property_set = NULL;
@@@ -222,10 -252,11 +253,11 @@@ void ETag_surfxml_storage___type(void
    memset(&storage_type,0,sizeof(storage_type));
  
    storage_type.content = A_surfxml_storage___type_content;
+   storage_type.content_type = A_surfxml_storage___type_content___type;
    storage_type.id = A_surfxml_storage___type_id;
    storage_type.model = A_surfxml_storage___type_model;
    storage_type.properties = current_property_set;
-   storage_type.size = surf_parse_get_int(A_surfxml_storage___type_size);
+   storage_type.size = surf_parse_get_size(A_surfxml_storage___type_size);
    sg_platf_new_storage_type(&storage_type);
    current_property_set = NULL;
  }
@@@ -252,7 -283,7 +284,7 @@@ void ETag_surfxml_mount(void
    memset(&mount,0,sizeof(mount));
  
    mount.name = A_surfxml_mount_name;
-   mount.id = A_surfxml_mount_id;
+   mount.storageId = A_surfxml_mount_storageId;
    sg_platf_new_mount(&mount);
  }
  
@@@ -393,16 -424,45 +425,45 @@@ void STag_surfxml_prop(void
  
  void ETag_surfxml_host(void)    {
    s_sg_platf_host_cbarg_t host;
+   char* buf;
    memset(&host,0,sizeof(host));
  
    host.properties = current_property_set;
  
    host.id = A_surfxml_host_id;
-   host.power_peak = get_cpu_power(A_surfxml_host_power);
+   buf = A_surfxml_host_power;
+   XBT_DEBUG("Buffer: %s", buf);
+   host.power_peak = xbt_dynar_new(sizeof(double), NULL);
+   if (strchr(buf, ',') == NULL){
+         double power_value = get_cpu_power(A_surfxml_host_power);
+         xbt_dynar_push_as(host.power_peak,double, power_value);
+   }
+   else {
+         xbt_dynar_t pstate_list = xbt_str_split(buf, ",");
+         int i;
+         for (i = 0; i < xbt_dynar_length(pstate_list); i++) {
+                 double power_value;
+                 char* power_value_str;
+                 xbt_dynar_get_cpy(pstate_list, i, &power_value_str);
+                 xbt_str_trim(power_value_str, NULL);
+                 power_value = get_cpu_power(power_value_str);
+                 xbt_dynar_push_as(host.power_peak, double, power_value);
+                 XBT_DEBUG("Power value: %f", power_value);
+         }
+         xbt_dynar_free(&pstate_list);
+   }
+   XBT_DEBUG("pstate: %s", A_surfxml_host_pstate);
+   //host.power_peak = get_cpu_power(A_surfxml_host_power);
    host.power_scale = surf_parse_get_double( A_surfxml_host_availability);
    host.core_amount = surf_parse_get_int(A_surfxml_host_core);
    host.power_trace = tmgr_trace_new_from_file(A_surfxml_host_availability___file);
    host.state_trace = tmgr_trace_new_from_file(A_surfxml_host_state___file);
+   host.pstate = surf_parse_get_int(A_surfxml_host_pstate);
    xbt_assert((A_surfxml_host_state == A_surfxml_host_state_ON) ||
          (A_surfxml_host_state == A_surfxml_host_state_OFF), "Invalid state");
    if (A_surfxml_host_state == A_surfxml_host_state_ON)
@@@ -542,10 -602,10 +603,10 @@@ void ETag_surfxml_link(void)
  
    link.id = A_surfxml_link_id;
    link.bandwidth = surf_parse_get_bandwidth(A_surfxml_link_bandwidth);
-   //printf("Link bandwidth [%lg]\n", link.bandwidth);  
+   //printf("Link bandwidth [%g]\n", link.bandwidth);
    link.bandwidth_trace = tmgr_trace_new_from_file(A_surfxml_link_bandwidth___file);
    link.latency = surf_parse_get_time(A_surfxml_link_latency);
-   //printf("Link latency [%lg]\n", link.latency);  
+   //printf("Link latency [%g]\n", link.latency);
    link.latency_trace = tmgr_trace_new_from_file(A_surfxml_link_latency___file);
  
    switch (A_surfxml_link_state) {
@@@ -801,13 -861,11 +862,11 @@@ void ETag_surfxml_AS(void)
    sg_platf_new_AS_end();
  }
  
- extern int _sg_init_status; /* FIXME: find a proper way to export this at some point */
  void STag_surfxml_config(void){
    AS_TAG = 0;
    xbt_assert(current_property_set == NULL, "Someone forgot to reset the property set to NULL in its closing tag (or XML malformed)");
    XBT_DEBUG("START configuration name = %s",A_surfxml_config_id);
-   if (_sg_init_status == 2) {
+   if (_sg_cfg_init_status == 2) {
      surf_parse_error("All <config> tags must be given before any platform elements (such as <AS>, <host>, <cluster>, <link>, etc).");
    }
  }
@@@ -1022,7 -1080,7 +1081,7 @@@ static void init_randomness(void
  
  static void add_randomness(void)
  {
-   /* If needed aditional properties can be added by using the prop tag */
+   /* If needed, additional properties can be added by using the prop tag */
    random_data_t random =
        random_new(random_generator, 0, random_min, random_max, random_mean,
                   random_std_deviation);
diff --combined src/surf/workstation.cpp
index 069500c,0000000..31aef93
mode 100644,000000..100644
--- /dev/null
@@@ -1,254 -1,0 +1,321 @@@
-   xbt_cfg_setdefault_boolean(_sg_cfg_set, "network/crosstraffic", xbt_strdup("yes"));
 +#include "workstation.hpp"
 +#include "simgrid/sg_config.h"
 +
 +extern "C" {
 +XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_workstation, surf,
 +                                "Logging specific to the SURF workstation module");
 +}
 +
 +WorkstationModelPtr surf_workstation_model = NULL;
 +
 +//FIXME:Faire hériter ou composer de cup et network
 +
 +/*************
 + * CallBacks *
 + *************/
 +
 +static void workstation_new(sg_platf_host_cbarg_t host){
 +  surf_workstation_model->createResource(host->id);
 +}
 +
 +/*********
 + * Model *
 + *********/
 +
 +void surf_workstation_model_init_current_default(void)
 +{
 +  surf_workstation_model = new WorkstationModel();
- StoragePtr WorkstationCLM03::findStorageOnMountList(const char* storage)
++  xbt_cfg_setdefault_boolean(_sg_cfg_set, "network/crosstraffic", "yes");
 +  surf_cpu_model_init_Cas01();
 +  surf_network_model_init_LegrandVelho();
 +
 +  ModelPtr model = static_cast<ModelPtr>(surf_workstation_model);
 +  xbt_dynar_push(model_list, &model);
 +  sg_platf_host_add_cb(workstation_new);
 +}
 +
 +void surf_workstation_model_init_compound()
 +{
 +
 +  xbt_assert(surf_cpu_model, "No CPU model defined yet!");
 +  xbt_assert(surf_network_model, "No network model defined yet!");
 +  surf_workstation_model = new WorkstationModel();
 +
 +  ModelPtr model = static_cast<ModelPtr>(surf_workstation_model);
 +  xbt_dynar_push(model_list, &model);
 +  sg_platf_host_add_cb(workstation_new);
 +}
 +
 +WorkstationModel::WorkstationModel() : Model("Workstation") {
 +}
 +
 +WorkstationModel::~WorkstationModel() {
 +}
 +
 +void WorkstationModel::parseInit(sg_platf_host_cbarg_t host){
 +  createResource(host->id);
 +}
 +
 +WorkstationCLM03Ptr WorkstationModel::createResource(string name){
 +
 +  WorkstationCLM03Ptr workstation = new WorkstationCLM03(surf_workstation_model, name.c_str(), NULL,
 +                (xbt_dynar_t)xbt_lib_get_or_null(storage_lib, name.c_str(), ROUTING_STORAGE_HOST_LEVEL),
 +                (RoutingEdgePtr)xbt_lib_get_or_null(host_lib, name.c_str(), ROUTING_HOST_LEVEL),
 +                dynamic_cast<CpuPtr>(static_cast<ResourcePtr>(xbt_lib_get_or_null(host_lib, name.c_str(), SURF_CPU_LEVEL))));
 +  XBT_DEBUG("Create workstation %s with %ld mounted disks", name.c_str(), xbt_dynar_length(workstation->p_storage));
 +  xbt_lib_set(host_lib, name.c_str(), SURF_WKS_LEVEL, static_cast<ResourcePtr>(workstation));
 +  return workstation;
 +}
 +
 +double WorkstationModel::shareResources(double now){
 +  return -1.0;
 +}
 +
 +void WorkstationModel::updateActionsState(double now, double delta){
 +  return;
 +}
 +
 +ActionPtr WorkstationModel::executeParallelTask(int workstation_nb,
 +                                        void **workstation_list,
 +                                        double *computation_amount,
 +                                        double *communication_amount,
 +                                        double rate){
 +#define cost_or_zero(array,pos) ((array)?(array)[pos]:0.0)
 +  if ((workstation_nb == 1)
 +      && (cost_or_zero(communication_amount, 0) == 0.0))
 +    return ((WorkstationCLM03Ptr)workstation_list[0])->execute(computation_amount[0]);
 +  else if ((workstation_nb == 1)
 +           && (cost_or_zero(computation_amount, 0) == 0.0))
 +    return communicate((WorkstationCLM03Ptr)workstation_list[0], (WorkstationCLM03Ptr)workstation_list[0],communication_amount[0], rate);
 +  else if ((workstation_nb == 2)
 +             && (cost_or_zero(computation_amount, 0) == 0.0)
 +             && (cost_or_zero(computation_amount, 1) == 0.0)) {
 +    int i,nb = 0;
 +    double value = 0.0;
 +
 +    for (i = 0; i < workstation_nb * workstation_nb; i++) {
 +      if (cost_or_zero(communication_amount, i) > 0.0) {
 +        nb++;
 +        value = cost_or_zero(communication_amount, i);
 +      }
 +    }
 +    if (nb == 1)
 +      return communicate((WorkstationCLM03Ptr)workstation_list[0], (WorkstationCLM03Ptr)workstation_list[1],value, rate);
 +  }
 +#undef cost_or_zero
 +
 +  THROW_UNIMPLEMENTED;          /* This model does not implement parallel tasks */
 +  return NULL;
 +}
 +
 +/* returns an array of network_link_CM02_t */
 +xbt_dynar_t WorkstationModel::getRoute(WorkstationCLM03Ptr src, WorkstationCLM03Ptr dst)
 +{
 +  XBT_DEBUG("ws_get_route");
 +  return surf_network_model->getRoute(src->p_netElm, dst->p_netElm);
 +}
 +
 +ActionPtr WorkstationModel::communicate(WorkstationCLM03Ptr src, WorkstationCLM03Ptr dst, double size, double rate){
 +  return surf_network_model->communicate(src->p_netElm, dst->p_netElm, size, rate);
 +}
 +
 +
 +
 +/************
 + * Resource *
 + ************/
 +WorkstationCLM03::WorkstationCLM03(WorkstationModelPtr model, const char* name, xbt_dict_t properties, xbt_dynar_t storage, RoutingEdgePtr netElm, CpuPtr cpu)
 +  : Resource(model, name, properties), p_storage(storage), p_netElm(netElm), p_cpu(cpu) {}
 +
 +bool WorkstationCLM03::isUsed(){
 +  THROW_IMPOSSIBLE;             /* This model does not implement parallel tasks */
 +  return -1;
 +}
 +
 +void WorkstationCLM03::updateState(tmgr_trace_event_t event_type, double value, double date){
 +  THROW_IMPOSSIBLE;             /* This model does not implement parallel tasks */
 +}
 +
 +ActionPtr WorkstationCLM03::execute(double size) {
 +  return p_cpu->execute(size);
 +}
 +
 +ActionPtr WorkstationCLM03::sleep(double duration) {
 +  return p_cpu->sleep(duration);
 +}
 +
 +e_surf_resource_state_t WorkstationCLM03::getState() {
 +  return p_cpu->getState();
 +}
 +
 +int WorkstationCLM03::getCore(){
 +  return p_cpu->getCore();
 +}
 +
 +double WorkstationCLM03::getSpeed(double load){
 +  return p_cpu->getSpeed(load);
 +}
 +
 +double WorkstationCLM03::getAvailableSpeed(){
 +  return p_cpu->getAvailableSpeed();
 +}
 +
++double WorkstationCLM03::getCurrentPowerPeak()
++{
++  return p_cpu->getCurrentPowerPeak();
++}
++
++double WorkstationCLM03::getPowerPeakAt(int pstate_index)
++{
++  return p_cpu->getPowerPeakAt(pstate_index);
++}
++
++int WorkstationCLM03::getNbPstates()
++{
++  return p_cpu->getNbPstates();
++}
++
++void WorkstationCLM03::setPowerPeakAt(int pstate_index)
++{
++      p_cpu->setPowerPeakAt(pstate_index);
++}
++
++double WorkstationCLM03::getConsumedEnergy()
++{
++  return p_cpu->getConsumedEnergy();
++}
++
++
 +xbt_dict_t WorkstationCLM03::getProperties()
 +{
 +  return p_cpu->m_properties;
 +}
 +
 +
-   XBT_DEBUG("Search for storage name '%s' on '%s'",storage,m_name);
++StoragePtr WorkstationCLM03::findStorageOnMountList(const char* mount)
 +{
 +  StoragePtr st = NULL;
 +  s_mount_t mnt;
 +  unsigned int cursor;
 +
-     if(!strcmp(storage,mnt.name)){
-       st = (StoragePtr)mnt.id;
++  XBT_DEBUG("Search for storage name '%s' on '%s'", mount, m_name);
 +  xbt_dynar_foreach(p_storage,cursor,mnt)
 +  {
 +    XBT_DEBUG("See '%s'",mnt.name);
-   if(!st) xbt_die("Can't find mount '%s' for '%s'",storage,m_name);
++    if(!strcmp(mount,mnt.name)){
++      st = dynamic_cast<StoragePtr>(static_cast<ResourcePtr>(mnt.storage));
 +      break;
 +    }
 +  }
-   StoragePtr st = findStorageOnMountList(fd->storage);
++  if(!st) xbt_die("Can't find mount '%s' for '%s'", mount, m_name);
 +  return st;
 +}
 +
++xbt_dict_t WorkstationCLM03::getStorageList()
++{
++  s_mount_t mnt;
++  unsigned int i;
++  xbt_dict_t storage_list = xbt_dict_new_homogeneous(NULL);
++  char *storage_name = NULL;
++
++  xbt_dynar_foreach(p_storage,i,mnt){
++    storage_name = (char *)dynamic_cast<StoragePtr>(static_cast<ResourcePtr>(mnt.storage))->m_name;
++    xbt_dict_set(storage_list,mnt.name,storage_name,NULL);
++  }
++  return storage_list;
++}
++
 +ActionPtr WorkstationCLM03::open(const char* mount, const char* path) {
 +  StoragePtr st = findStorageOnMountList(mount);
 +  XBT_DEBUG("OPEN on disk '%s'", st->m_name);
 +  return st->open(mount, path);
 +}
 +
 +ActionPtr WorkstationCLM03::close(surf_file_t fd) {
- ActionPtr WorkstationCLM03::read(void* ptr, size_t size, surf_file_t fd) {
-   StoragePtr st = findStorageOnMountList(fd->storage);
++  StoragePtr st = findStorageOnMountList(fd->mount);
 +  XBT_DEBUG("CLOSE on disk '%s'",st->m_name);
 +  return st->close(fd);
 +}
 +
-   return st->read(ptr, size, fd);
++ActionPtr WorkstationCLM03::read(surf_file_t fd, sg_storage_size_t size) {
++  StoragePtr st = findStorageOnMountList(fd->mount);
 +  XBT_DEBUG("READ on disk '%s'",st->m_name);
- ActionPtr WorkstationCLM03::write(const void* ptr, size_t size, surf_file_t fd) {
-   StoragePtr st = findStorageOnMountList(fd->storage);
++  return st->read(fd, size);
 +}
 +
-   return st->write(ptr, size, fd);
++ActionPtr WorkstationCLM03::write(surf_file_t fd, sg_storage_size_t size) {
++  StoragePtr st = findStorageOnMountList(fd->mount);
 +  XBT_DEBUG("WRITE on disk '%s'",st->m_name);
-     StoragePtr st = findStorageOnMountList(fd->storage);
++  return st->write(fd, size);
 +}
 +
 +int WorkstationCLM03::unlink(surf_file_t fd) {
 +  if (!fd){
 +    XBT_WARN("No such file descriptor. Impossible to unlink");
 +    return 0;
 +  } else {
 +//    XBT_INFO("%s %zu", fd->storage, fd->size);
-       free(fd->storage);
++    StoragePtr st = findStorageOnMountList(fd->mount);
 +    /* Check if the file is on this storage */
 +    if (!xbt_dict_get_or_null(st->p_content, fd->name)){
 +      XBT_WARN("File %s is not on disk %s. Impossible to unlink", fd->name,
 +          st->m_name);
 +      return 0;
 +    } else {
 +      XBT_DEBUG("UNLINK on disk '%s'",st->m_name);
 +      st->m_usedSize -= fd->size;
 +
 +      // Remove the file from storage
 +      xbt_dict_remove(st->p_content, fd->name);
 +
 +      free(fd->name);
- size_t WorkstationCLM03::getSize(surf_file_t fd){
++      free(fd->mount);
 +      xbt_free(fd);
 +      return 1;
 +    }
 +  }
 +}
 +
 +ActionPtr WorkstationCLM03::ls(const char* mount, const char *path){
 +  XBT_DEBUG("LS on mount '%s' and file '%s'", mount, path);
 +  StoragePtr st = findStorageOnMountList(mount);
 +  return st->ls(path);
 +}
 +
++sg_storage_size_t WorkstationCLM03::getSize(surf_file_t fd){
 +  return fd->size;
 +}
 +
++xbt_dynar_t WorkstationCLM03::getInfo( surf_file_t fd)
++{
++  StoragePtr st = findStorageOnMountList(fd->mount);
++  sg_storage_size_t *psize = xbt_new(sg_storage_size_t, 1);
++  *psize = fd->size;
++  xbt_dynar_t info = xbt_dynar_new(sizeof(void*), NULL);
++  xbt_dynar_push_as(info, sg_storage_size_t *, psize);
++  xbt_dynar_push_as(info, void *, fd->mount);
++  xbt_dynar_push_as(info, void *, (void *)st->m_name);
++  xbt_dynar_push_as(info, void *, st->p_typeId);
++  xbt_dynar_push_as(info, void *, st->p_contentType);
++
++  return info;
++}
++
++sg_storage_size_t WorkstationCLM03::getFreeSize(const char* name)
++{
++  StoragePtr st = findStorageOnMountList(name);
++  return st->m_size - st->m_usedSize;
++}
++
++sg_storage_size_t WorkstationCLM03::getUsedSize(const char* name)
++{
++  StoragePtr st = findStorageOnMountList(name);
++  return st->m_usedSize;
++}
++
 +e_surf_resource_state_t WorkstationCLM03Lmm::getState() {
 +  return WorkstationCLM03::getState();
 +}
 +/**********
 + * Action *
 + **********/
diff --combined src/surf/workstation.hpp
index 675cfad,0000000..08940e0
mode 100644,000000..100644
--- /dev/null
@@@ -1,112 -1,0 +1,122 @@@
-   size_t getSize(surf_file_t fd);
-   ActionPtr read(void* ptr, size_t size, surf_file_t fd);
-   ActionPtr write(const void* ptr, size_t size, surf_file_t fd);
 +#include "surf.hpp"
 +#include "storage.hpp"
 +#include "cpu.hpp"
 +#include "network.hpp"
 +
 +#ifndef WORKSTATION_HPP_
 +#define WORKSTATION_HPP_
 +
 +/***********
 + * Classes *
 + ***********/
 +
 +class WorkstationModel;
 +typedef WorkstationModel *WorkstationModelPtr;
 +
 +class WorkstationCLM03;
 +typedef WorkstationCLM03 *WorkstationCLM03Ptr;
 +
 +class WorkstationCLM03Lmm;
 +typedef WorkstationCLM03Lmm *WorkstationCLM03LmmPtr;
 +
 +class WorkstationAction;
 +typedef WorkstationAction *WorkstationActionPtr;
 +
 +/*FIXME:class WorkstationActionLmm;
 +typedef WorkstationActionLmm *WorkstationActionLmmPtr;*/
 +
 +/*********
 + * Tools *
 + *********/
 +extern WorkstationModelPtr surf_workstation_model;
 +
 +/*********
 + * Model *
 + *********/
 +class WorkstationModel : public Model {
 +public:
 +  WorkstationModel(string name): Model(name) {};
 +  WorkstationModel();
 +  ~WorkstationModel();
 +  virtual void parseInit(sg_platf_host_cbarg_t host);
 +  WorkstationCLM03Ptr createResource(string name);
 +  double shareResources(double now);
 +  void updateActionsState(double now, double delta);
 +
 +  virtual ActionPtr executeParallelTask(int workstation_nb,
 +                                        void **workstation_list,
 +                                        double *computation_amount,
 +                                        double *communication_amount,
 +                                        double rate);
 + virtual xbt_dynar_t getRoute(WorkstationCLM03Ptr src, WorkstationCLM03Ptr dst);
 + virtual ActionPtr communicate(WorkstationCLM03Ptr src, WorkstationCLM03Ptr dst, double size, double rate);
 +};
 +
 +/************
 + * Resource *
 + ************/
 +
 +class WorkstationCLM03 : virtual public Resource {
 +public:
 +  WorkstationCLM03(WorkstationModelPtr model, const char* name, xbt_dict_t properties, xbt_dynar_t storage, RoutingEdgePtr netElm, CpuPtr cpu);
 +
 +  void updateState(tmgr_trace_event_t event_type, double value, double date);
 +
 +  virtual ActionPtr execute(double size);
 +  virtual ActionPtr sleep(double duration);
 +  e_surf_resource_state_t getState();
 +
 +  virtual int getCore();
 +  virtual double getSpeed(double load);
 +  virtual double getAvailableSpeed();
++  virtual double getCurrentPowerPeak();
++  virtual double getPowerPeakAt(int pstate_index);
++  virtual int getNbPstates();
++  virtual void setPowerPeakAt(int pstate_index);
++  virtual double getConsumedEnergy();
 +
 +  xbt_dict_t getProperties();
 +
 +  StoragePtr findStorageOnMountList(const char* storage);
++  xbt_dict_t getStorageList();
 +  ActionPtr open(const char* mount, const char* path);
 +  ActionPtr close(surf_file_t fd);
 +  int unlink(surf_file_t fd);
 +  ActionPtr ls(const char* mount, const char *path);
++  sg_storage_size_t getSize(surf_file_t fd);
++  ActionPtr read(surf_file_t fd, sg_storage_size_t size);
++  ActionPtr write(surf_file_t fd, sg_storage_size_t size);
++  xbt_dynar_t getInfo( surf_file_t fd);
++  sg_storage_size_t getFreeSize(const char* name);
++  sg_storage_size_t getUsedSize(const char* name);
++
 +  bool isUsed();
 +  //bool isShared();
 +  xbt_dynar_t p_storage;
 +  RoutingEdgePtr p_netElm;
 +  CpuPtr p_cpu;
 +  NetworkCm02LinkPtr p_network;
 +};
 +
 +class WorkstationCLM03Lmm : public WorkstationCLM03, public ResourceLmm {
 +public:
 +  WorkstationCLM03Lmm(WorkstationModelPtr model, const char* name, xbt_dict_t props, xbt_dynar_t storage, RoutingEdgePtr netElm, CpuPtr cpu):
 +        WorkstationCLM03(model, name, props, storage, netElm, cpu){};
 +  e_surf_resource_state_t getState();
 +};
 +
 +/**********
 + * Action *
 + **********/
 +class WorkstationAction : virtual public Action {
 +public:
 +  WorkstationAction(ModelPtr model, double cost, bool failed): Action(model, cost, failed) {};
 +};
 +
 +class WorkstationActionLmm : public ActionLmm, public WorkstationAction {
 +public:
 +  WorkstationActionLmm(ModelPtr model, double cost, bool failed): ActionLmm(model, cost, failed), WorkstationAction(model, cost, failed) {};
 +};
 +
 +
 +#endif /* WORKSTATION_HPP_ */
index 8f11693,0000000..507d25e
mode 100644,000000..100644
--- /dev/null
@@@ -1,834 -1,0 +1,861 @@@
-       host->power_peak,
 +/* Copyright (c) 2007, 2008, 2009, 2010. The SimGrid Team.
 + * All rights reserved.                                                     */
 +
 +/* This program is free software; you can redistribute it and/or modify it
 + * under the terms of the license (GNU LGPL) which comes with this package. */
 +
 +#include "workstation_ptask_L07.hpp"
 +#include "cpu.hpp"
 +#include "surf_routing.hpp"
 +
 +XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(surf_workstation);
 +
 +static int ptask_host_count = 0;
 +static xbt_dict_t ptask_parallel_task_link_set = NULL;
 +lmm_system_t ptask_maxmin_system = NULL;
 +
 +WorkstationL07Model::WorkstationL07Model() : WorkstationModel("Workstation ptask_L07") {
 +  if (!ptask_maxmin_system)
 +      ptask_maxmin_system = lmm_system_new(1);
 +  surf_workstation_model = NULL;
 +  surf_network_model = new NetworkL07Model();
 +  surf_cpu_model = new CpuL07Model();
 +  routing_model_create(p_networkModel->createResource("__loopback__",
 +                                                        498000000, NULL,
 +                                                        0.000015, NULL,
 +                                                        SURF_RESOURCE_ON, NULL,
 +                                                        SURF_LINK_FATPIPE, NULL));
 +}
 +
 +WorkstationL07Model::~WorkstationL07Model() {
 +  xbt_dict_free(&ptask_parallel_task_link_set);
 +
 +  delete surf_cpu_model;
 +  delete surf_network_model;
 +  ptask_host_count = 0;
 +
 +  if (ptask_maxmin_system) {
 +    lmm_system_free(ptask_maxmin_system);
 +    ptask_maxmin_system = NULL;
 +  }
 +}
 +
 +double WorkstationL07Model::shareResources(double now)
 +{
 +  void *_action;
 +  WorkstationL07ActionLmmPtr action;
 +
 +  xbt_swag_t running_actions = this->p_runningActionSet;
 +  double min = this->shareResourcesMaxMin(running_actions,
 +                                              ptask_maxmin_system,
 +                                              bottleneck_solve);
 +
 +  xbt_swag_foreach(_action, running_actions) {
 +      action = dynamic_cast<WorkstationL07ActionLmmPtr>(static_cast<ActionPtr>(_action));
 +    if (action->m_latency > 0) {
 +      if (min < 0) {
 +        min = action->m_latency;
 +        XBT_DEBUG("Updating min (value) with %p (start %f): %f", action,
 +               action->m_start, min);
 +      } else if (action->m_latency < min) {
 +        min = action->m_latency;
 +        XBT_DEBUG("Updating min (latency) with %p (start %f): %f", action,
 +               action->m_start, min);
 +      }
 +    }
 +  }
 +
 +  XBT_DEBUG("min value : %f", min);
 +
 +  return min;
 +}
 +
 +void WorkstationL07Model::updateActionsState(double now, double delta)
 +{
 +  double deltap = 0.0;
 +  void *_action, *_next_action;
 +  WorkstationL07ActionLmmPtr action;
 +
 +  xbt_swag_foreach_safe(_action, _next_action, p_runningActionSet) {
 +    action = dynamic_cast<WorkstationL07ActionLmmPtr>(static_cast<ActionPtr>(_action));
 +
 +    deltap = delta;
 +    if (action->m_latency > 0) {
 +      if (action->m_latency > deltap) {
 +        double_update(&(action->m_latency), deltap);
 +        deltap = 0.0;
 +      } else {
 +        double_update(&(deltap), action->m_latency);
 +        action->m_latency = 0.0;
 +      }
 +      if ((action->m_latency == 0.0) && (action->m_suspended == 0)) {
 +        action->updateBound();
 +        lmm_update_variable_weight(ptask_maxmin_system, action->p_variable, 1.0);
 +      }
 +    }
 +    XBT_DEBUG("Action (%p) : remains (%g) updated by %g.",
 +           action, action->m_remains, lmm_variable_getvalue(action->p_variable) * delta);
 +    double_update(&(action->m_remains), lmm_variable_getvalue(action->p_variable) * delta);
 +
 +    if (action->m_maxDuration != NO_MAX_DURATION)
 +      double_update(&(action->m_maxDuration), delta);
 +
 +    XBT_DEBUG("Action (%p) : remains (%g).",
 +           action, action->m_remains);
 +    if ((action->m_remains <= 0) &&
 +        (lmm_get_variable_weight(action->p_variable) > 0)) {
 +      action->m_finish = surf_get_clock();
 +      action->setState(SURF_ACTION_DONE);
 +    } else if ((action->m_maxDuration != NO_MAX_DURATION) &&
 +               (action->m_maxDuration <= 0)) {
 +      action->m_finish = surf_get_clock();
 +     action->setState(SURF_ACTION_DONE);
 +    } else {
 +      /* Need to check that none of the model has failed */
 +      lmm_constraint_t cnst = NULL;
 +      int i = 0;
 +      void *constraint_id = NULL;
 +
 +      while ((cnst = lmm_get_cnst_from_var(ptask_maxmin_system, action->p_variable,
 +                                    i++))) {
 +        constraint_id = lmm_constraint_id(cnst);
 +
 +        if (static_cast<WorkstationCLM03LmmPtr>(constraint_id)->p_stateCurrent == SURF_RESOURCE_OFF) {
 +          XBT_DEBUG("Action (%p) Failed!!", action);
 +          action->m_finish = surf_get_clock();
 +          action->setState(SURF_ACTION_FAILED);
 +          break;
 +        }
 +      }
 +    }
 +  }
 +  return;
 +}
 +
 +ActionPtr WorkstationL07Model::executeParallelTask(int workstation_nb,
 +                                                   void **workstation_list,
 +                                                 double
 +                                                 *computation_amount, double
 +                                                 *communication_amount,
 +                                                 double rate)
 +{
 +  WorkstationL07ActionLmmPtr action;
 +  int i, j;
 +  unsigned int cpt;
 +  int nb_link = 0;
 +  int nb_host = 0;
 +  double latency = 0.0;
 +
 +  if (ptask_parallel_task_link_set == NULL)
 +    ptask_parallel_task_link_set = xbt_dict_new_homogeneous(NULL);
 +
 +  xbt_dict_reset(ptask_parallel_task_link_set);
 +
 +  /* Compute the number of affected resources... */
 +  for (i = 0; i < workstation_nb; i++) {
 +    for (j = 0; j < workstation_nb; j++) {
 +      xbt_dynar_t route=NULL;
 +
 +      if (communication_amount[i * workstation_nb + j] > 0) {
 +        double lat=0.0;
 +        unsigned int cpt;
 +        void *_link;
 +        LinkL07Ptr link;
 +
 +        routing_platf->getRouteAndLatency(dynamic_cast<WorkstationL07Ptr>(
 +                                                 static_cast<ResourcePtr>(
 +                                                  workstation_list[i]))->p_netElm,
 +                                                dynamic_cast<WorkstationL07Ptr>(
 +                                                 static_cast<ResourcePtr>(
 +                                                      workstation_list[j]))->p_netElm,
 +                                                &route,
 +                                                &lat);
 +        latency = MAX(latency, lat);
 +
 +        xbt_dynar_foreach(route, cpt, _link) {
 +           link = dynamic_cast<LinkL07Ptr>(static_cast<ResourcePtr>(_link));
 +           xbt_dict_set(ptask_parallel_task_link_set, link->m_name, link, NULL);
 +        }
 +      }
 +    }
 +  }
 +
 +  nb_link = xbt_dict_length(ptask_parallel_task_link_set);
 +  xbt_dict_reset(ptask_parallel_task_link_set);
 +
 +  for (i = 0; i < workstation_nb; i++)
 +    if (computation_amount[i] > 0)
 +      nb_host++;
 +
 +  action = new WorkstationL07ActionLmm(this, 1, 0);
 +  XBT_DEBUG("Creating a parallel task (%p) with %d cpus and %d links.",
 +         action, workstation_nb, nb_link);
 +  action->m_suspended = 0;        /* Should be useless because of the
 +                                   calloc but it seems to help valgrind... */
 +  action->m_workstationNb = workstation_nb;
 +  action->p_workstationList = (WorkstationCLM03Ptr *) workstation_list;
 +  action->p_computationAmount = computation_amount;
 +  action->p_communicationAmount = communication_amount;
 +  action->m_latency = latency;
 +  action->m_rate = rate;
 +
 +  action->p_variable = lmm_variable_new(ptask_maxmin_system, action, 1.0,
 +                       (action->m_rate > 0) ? action->m_rate : -1.0,
 +                       workstation_nb + nb_link);
 +
 +  if (action->m_latency > 0)
 +    lmm_update_variable_weight(ptask_maxmin_system, action->p_variable, 0.0);
 +
 +  for (i = 0; i < workstation_nb; i++)
 +    lmm_expand(ptask_maxmin_system,
 +             static_cast<CpuLmmPtr>(dynamic_cast<WorkstationL07Ptr>(
 +                                         static_cast<ResourcePtr>(workstation_list[i]))->p_cpu)->p_constraint,
 +               action->p_variable, computation_amount[i]);
 +
 +  for (i = 0; i < workstation_nb; i++) {
 +    for (j = 0; j < workstation_nb; j++) {
 +      void *_link;
 +      LinkL07Ptr link;
 +
 +      xbt_dynar_t route=NULL;
 +      if (communication_amount[i * workstation_nb + j] == 0.0)
 +        continue;
 +
 +      routing_platf->getRouteAndLatency(dynamic_cast<WorkstationL07Ptr>(
 +                                         static_cast<ResourcePtr>(workstation_list[i]))->p_netElm,
 +                                        dynamic_cast<WorkstationL07Ptr>(
 +                                         static_cast<ResourcePtr>(workstation_list[j]))->p_netElm,
 +                                          &route, NULL);
 +
 +      xbt_dynar_foreach(route, cpt, _link) {
 +        link = dynamic_cast<LinkL07Ptr>(static_cast<ResourcePtr>(_link));
 +        lmm_expand_add(ptask_maxmin_system, link->p_constraint,
 +                       action->p_variable,
 +                       communication_amount[i * workstation_nb + j]);
 +      }
 +    }
 +  }
 +
 +  if (nb_link + nb_host == 0) {
 +    action->m_cost = 1.0;
 +    action->m_remains = 0.0;
 +  }
 +
 +  return static_cast<ActionPtr>(action);
 +}
 +
 +ResourcePtr WorkstationL07Model::createResource(const char *name, double power_scale,
 +                               double power_initial,
 +                               tmgr_trace_t power_trace,
 +                               e_surf_resource_state_t state_initial,
 +                               tmgr_trace_t state_trace,
 +                               xbt_dict_t cpu_properties)
 +{
 +  WorkstationL07Ptr wk = NULL;
 +  xbt_assert(!surf_workstation_resource_priv(surf_workstation_resource_by_name(name)),
 +              "Host '%s' declared several times in the platform file.",
 +              name);
 +
 +  wk = new WorkstationL07(this, name, cpu_properties,
 +                                static_cast<RoutingEdgePtr>(xbt_lib_get_or_null(host_lib, name, ROUTING_HOST_LEVEL)),
 +                                dynamic_cast<CpuPtr>(static_cast<ResourcePtr>(xbt_lib_get_or_null(host_lib, name, SURF_CPU_LEVEL))));
 +
 +  xbt_lib_set(host_lib, name, SURF_WKS_LEVEL, static_cast<ResourcePtr>(wk));
 +
 +  return wk;//FIXME:xbt_lib_get_elm_or_null(host_lib, name);
 +}
 +
 +ActionPtr WorkstationL07Model::communicate(WorkstationCLM03Ptr src, WorkstationCLM03Ptr dst,
 +                                       double size, double rate)
 +{
 +  void **workstation_list = xbt_new0(void *, 2);
 +  double *computation_amount = xbt_new0(double, 2);
 +  double *communication_amount = xbt_new0(double, 4);
 +  ActionPtr res = NULL;
 +
 +  workstation_list[0] = static_cast<ResourcePtr>(src);
 +  workstation_list[1] = static_cast<ResourcePtr>(dst);
 +  communication_amount[1] = size;
 +
 +  res = executeParallelTask(2, workstation_list,
 +                                    computation_amount,
 +                                    communication_amount, rate);
 +
 +  return res;
 +}
 +
 +xbt_dynar_t WorkstationL07Model::getRoute(WorkstationCLM03Ptr src, WorkstationCLM03Ptr dst)
 +{
 +  xbt_dynar_t route=NULL;
 +  routing_platf->getRouteAndLatency(src->p_netElm, dst->p_netElm, &route, NULL);
 +  return route;
 +}
 +
 +ResourcePtr CpuL07Model::createResource(const char *name, double power_scale,
 +                               double power_initial,
 +                               tmgr_trace_t power_trace,
 +                               e_surf_resource_state_t state_initial,
 +                               tmgr_trace_t state_trace,
 +                               xbt_dict_t cpu_properties)
 +{
 +  CpuL07Ptr cpu = NULL;
 +  xbt_assert(!surf_workstation_resource_priv(surf_workstation_resource_by_name(name)),
 +              "Host '%s' declared several times in the platform file.",
 +              name);
 +
 +  cpu = new CpuL07(this, name, cpu_properties);
 +
 +  cpu->p_power.scale = power_scale;
 +  xbt_assert(cpu->p_power.scale > 0, "Power has to be >0");
 +
 +  cpu->m_powerCurrent = power_initial;
 +  if (power_trace)
 +    cpu->p_power.event =
 +        tmgr_history_add_trace(history, power_trace, 0.0, 0, static_cast<ResourcePtr>(cpu));
 +
 +  cpu->p_stateCurrent = state_initial;
 +  if (state_trace)
 +    cpu->p_stateEvent =
 +        tmgr_history_add_trace(history, state_trace, 0.0, 0, static_cast<ResourcePtr>(cpu));
 +
 +  cpu->p_constraint =
 +      lmm_constraint_new(ptask_maxmin_system, cpu,
 +                         cpu->m_powerCurrent * cpu->p_power.scale);
 +
 +  xbt_lib_set(host_lib, name, SURF_CPU_LEVEL, static_cast<ResourcePtr>(cpu));
 +
 +  return cpu;//FIXME:xbt_lib_get_elm_or_null(host_lib, name);
 +}
 +
 +ResourcePtr NetworkL07Model::createResource(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)
 +{
 +  LinkL07Ptr nw_link = new LinkL07(this, xbt_strdup(name), properties);
 +  xbt_assert(!xbt_lib_get_or_null(link_lib, name, SURF_LINK_LEVEL),
 +              "Link '%s' declared several times in the platform file.",
 +              name);
 +
 +  nw_link->m_bwCurrent = bw_initial;
 +  if (bw_trace)
 +    nw_link->p_bwEvent =
 +        tmgr_history_add_trace(history, bw_trace, 0.0, 0, static_cast<ResourcePtr>(nw_link));
 +  nw_link->p_stateCurrent = state_initial;
 +  nw_link->m_latCurrent = lat_initial;
 +  if (lat_trace)
 +    nw_link->p_latEvent =
 +        tmgr_history_add_trace(history, lat_trace, 0.0, 0, static_cast<ResourcePtr>(nw_link));
 +  if (state_trace)
 +    nw_link->p_stateEvent =
 +        tmgr_history_add_trace(history, state_trace, 0.0, 0, static_cast<ResourcePtr>(nw_link));
 +
 +  nw_link->p_constraint =
 +      lmm_constraint_new(ptask_maxmin_system, nw_link,
 +                         nw_link->m_bwCurrent);
 +
 +  if (policy == SURF_LINK_FATPIPE)
 +    lmm_constraint_shared(nw_link->p_constraint);
 +
 +  xbt_lib_set(link_lib, name, SURF_LINK_LEVEL, static_cast<ResourcePtr>(nw_link));
 +  return nw_link;
 +}
 +
 +void WorkstationL07Model::addTraces()
 +{
 +  xbt_dict_cursor_t cursor = NULL;
 +  char *trace_name, *elm;
 +
 +  if (!trace_connect_list_host_avail)
 +    return;
 +
 +  /* Connect traces relative to cpu */
 +  xbt_dict_foreach(trace_connect_list_host_avail, cursor, trace_name, elm) {
 +    tmgr_trace_t trace = (tmgr_trace_t) xbt_dict_get_or_null(traces_set_list, trace_name);
 +    CpuL07Ptr host = dynamic_cast<CpuL07Ptr>(
 +                         static_cast<ResourcePtr>(
 +                           surf_cpu_resource_priv(
 +                             surf_cpu_resource_by_name(elm))));
 +
 +    xbt_assert(host, "Host %s undefined", elm);
 +    xbt_assert(trace, "Trace %s undefined", trace_name);
 +
 +    host->p_stateEvent = tmgr_history_add_trace(history, trace, 0.0, 0, static_cast<ResourcePtr>(host));
 +  }
 +
 +  xbt_dict_foreach(trace_connect_list_power, cursor, trace_name, elm) {
 +    tmgr_trace_t trace = (tmgr_trace_t) xbt_dict_get_or_null(traces_set_list, trace_name);
 +    CpuL07Ptr host = dynamic_cast<CpuL07Ptr>(
 +                         static_cast<ResourcePtr>(
 +                           surf_cpu_resource_priv(
 +                             surf_cpu_resource_by_name(elm))));
 +
 +    xbt_assert(host, "Host %s undefined", elm);
 +    xbt_assert(trace, "Trace %s undefined", trace_name);
 +
 +    host->p_power.event = tmgr_history_add_trace(history, trace, 0.0, 0, static_cast<ResourcePtr>(host));
 +  }
 +
 +  /* Connect traces relative to network */
 +  xbt_dict_foreach(trace_connect_list_link_avail, cursor, trace_name, elm) {
 +    tmgr_trace_t trace = (tmgr_trace_t) xbt_dict_get_or_null(traces_set_list, trace_name);
 +    LinkL07Ptr link = dynamic_cast<LinkL07Ptr>(static_cast<ResourcePtr>(xbt_lib_get_or_null(link_lib, elm, SURF_LINK_LEVEL)));
 +
 +    xbt_assert(link, "Link %s undefined", elm);
 +    xbt_assert(trace, "Trace %s undefined", trace_name);
 +
 +    link->p_stateEvent = tmgr_history_add_trace(history, trace, 0.0, 0, static_cast<ResourcePtr>(link));
 +  }
 +
 +  xbt_dict_foreach(trace_connect_list_bandwidth, cursor, trace_name, elm) {
 +    tmgr_trace_t trace = (tmgr_trace_t) xbt_dict_get_or_null(traces_set_list, trace_name);
 +    LinkL07Ptr link = dynamic_cast<LinkL07Ptr>(static_cast<ResourcePtr>(xbt_lib_get_or_null(link_lib, elm, SURF_LINK_LEVEL)));
 +
 +    xbt_assert(link, "Link %s undefined", elm);
 +    xbt_assert(trace, "Trace %s undefined", trace_name);
 +
 +    link->p_bwEvent = tmgr_history_add_trace(history, trace, 0.0, 0, static_cast<ResourcePtr>(link));
 +  }
 +
 +  xbt_dict_foreach(trace_connect_list_latency, cursor, trace_name, elm) {
 +    tmgr_trace_t trace = (tmgr_trace_t) xbt_dict_get_or_null(traces_set_list, trace_name);
 +    LinkL07Ptr link = dynamic_cast<LinkL07Ptr>(static_cast<ResourcePtr>(xbt_lib_get_or_null(link_lib, elm, SURF_LINK_LEVEL)));
 +
 +    xbt_assert(link, "Link %s undefined", elm);
 +    xbt_assert(trace, "Trace %s undefined", trace_name);
 +
 +    link->p_latEvent = tmgr_history_add_trace(history, trace, 0.0, 0, static_cast<ResourcePtr>(link));
 +  }
 +}
 +
 +/************
 + * Resource *
 + ************/
 +
 +WorkstationL07::WorkstationL07(WorkstationModelPtr model, const char* name, xbt_dict_t props, RoutingEdgePtr netElm, CpuPtr cpu)
 +  : Resource(model, name, props), WorkstationCLM03Lmm(model, name, props, NULL, netElm, cpu)
 +{
 +}
 +
++double WorkstationL07::getPowerPeakAt(int pstate_index)
++{
++      XBT_DEBUG("[ws_get_power_peak_at] Not implemented for workstation_ptask_L07");
++      return 0.0;
++}
++
++int WorkstationL07::getNbPstates()
++{
++      XBT_DEBUG("[ws_get_nb_pstates] Not implemented for workstation_ptask_L07");
++      return 0.0;
++}
++
++void WorkstationL07::setPowerPeakAt(int pstate_index)
++{
++      XBT_DEBUG("[ws_set_power_peak_at] Not implemented for workstation_ptask_L07");
++}
++
++double WorkstationL07::getConsumedEnergy()
++{
++      XBT_DEBUG("[ws_get_consumed_energy] Not implemented for workstation_ptask_L07");
++      return 0.0;
++}
++
 +CpuL07::CpuL07(CpuL07ModelPtr model, const char* name, xbt_dict_t props)
 + : Resource(model, name, props), CpuLmm(model, name, props) {
 +
 +}
 +
 +LinkL07::LinkL07(NetworkL07ModelPtr model, const char* name, xbt_dict_t props)
 + : Resource(model, name, props), NetworkCm02LinkLmm(model, name, props) {
 +
 +}
 +
 +bool CpuL07::isUsed(){
 +  return lmm_constraint_used(ptask_maxmin_system, p_constraint);
 +}
 +
 +bool LinkL07::isUsed(){
 +  return lmm_constraint_used(ptask_maxmin_system, p_constraint);
 +}
 +
 +void CpuL07::updateState(tmgr_trace_event_t event_type, double value, double date){
 +  XBT_DEBUG("Updating cpu %s (%p) with value %g", m_name, this, value);
 +  if (event_type == p_power.event) {
 +      m_powerCurrent = value;
 +    lmm_update_constraint_bound(ptask_maxmin_system, p_constraint, m_powerCurrent * p_power.scale);
 +    if (tmgr_trace_event_free(event_type))
 +      p_power.event = NULL;
 +  } else if (event_type == p_stateEvent) {
 +    if (value > 0)
 +      p_stateCurrent = SURF_RESOURCE_ON;
 +    else
 +      p_stateCurrent = SURF_RESOURCE_OFF;
 +    if (tmgr_trace_event_free(event_type))
 +      p_stateEvent = NULL;
 +  } else {
 +    XBT_CRITICAL("Unknown event ! \n");
 +    xbt_abort();
 +  }
 +  return;
 +}
 +
 +void LinkL07::updateState(tmgr_trace_event_t event_type, double value, double date){
 +  XBT_DEBUG("Updating link %s (%p) with value=%f for date=%g", m_name, this, value, date);
 +  if (event_type == p_bwEvent) {
 +    m_bwCurrent = value;
 +    lmm_update_constraint_bound(ptask_maxmin_system, p_constraint, m_bwCurrent);
 +    if (tmgr_trace_event_free(event_type))
 +      p_bwEvent = NULL;
 +  } else if (event_type == p_latEvent) {
 +    lmm_variable_t var = NULL;
 +    WorkstationL07ActionLmmPtr action;
 +    lmm_element_t elem = NULL;
 +
 +    m_latCurrent = value;
 +    while ((var = lmm_get_var_from_cnst(ptask_maxmin_system, p_constraint, &elem))) {
 +      action = (WorkstationL07ActionLmmPtr) lmm_variable_id(var);
 +      action->updateBound();
 +    }
 +    if (tmgr_trace_event_free(event_type))
 +      p_latEvent = NULL;
 +  } else if (event_type == p_stateEvent) {
 +    if (value > 0)
 +      p_stateCurrent = SURF_RESOURCE_ON;
 +    else
 +      p_stateCurrent = SURF_RESOURCE_OFF;
 +    if (tmgr_trace_event_free(event_type))
 +      p_stateEvent = NULL;
 +  } else {
 +    XBT_CRITICAL("Unknown event ! \n");
 +    xbt_abort();
 +  }
 +  return;
 +}
 +
 +e_surf_resource_state_t WorkstationL07::getState()
 +{
 +  return p_cpu->p_stateCurrent;
 +}
 +
 +e_surf_resource_state_t CpuL07::getState()
 +{
 +  return p_stateCurrent;
 +}
 +
 +double CpuL07::getSpeed(double load)
 +{
 +  return load * p_power.scale;
 +}
 +
 +double CpuL07::getAvailableSpeed()
 +{
 +  return m_powerCurrent;
 +}
 +
 +ActionPtr WorkstationL07::execute(double size)
 +{
 +  void **workstation_list = xbt_new0(void *, 1);
 +  double *computation_amount = xbt_new0(double, 1);
 +  double *communication_amount = xbt_new0(double, 1);
 +
 +  workstation_list[0] = static_cast<ResourcePtr>(this);
 +  communication_amount[0] = 0.0;
 +  computation_amount[0] = size;
 +
 +  return static_cast<WorkstationL07ModelPtr>(p_model)->executeParallelTask(1, workstation_list,
 +                                            computation_amount,
 +                                     communication_amount, -1);
 +}
 +
 +ActionPtr WorkstationL07::sleep(double duration)
 +{
 +  WorkstationL07ActionLmmPtr action = NULL;
 +
 +  XBT_IN("(%s,%g)", m_name, duration);
 +
 +  action = dynamic_cast<WorkstationL07ActionLmmPtr>(execute(1.0));
 +  action->m_maxDuration = duration;
 +  action->m_suspended = 2;
 +  lmm_update_variable_weight(ptask_maxmin_system, action->p_variable, 0.0);
 +
 +  XBT_OUT();
 +  return action;
 +}
 +
 +double LinkL07::getBandwidth()
 +{
 +  return m_bwCurrent;
 +}
 +
 +double LinkL07::getLatency()
 +{
 +  return m_latCurrent;
 +}
 +
 +bool LinkL07::isShared()
 +{
 +  return lmm_constraint_is_shared(p_constraint);
 +}
 +
 +/**********
 + * Action *
 + **********/
 +
 +WorkstationL07ActionLmm::~WorkstationL07ActionLmm(){
 +  free(p_workstationList);
 +  free(p_communicationAmount);
 +  free(p_computationAmount);
 +#ifdef HAVE_TRACING
 +  xbt_free(p_category);
 +#endif
 +}
 +
 +void WorkstationL07ActionLmm::updateBound()
 +{
 +  double lat_current = 0.0;
 +  double lat_bound = -1.0;
 +  int i, j;
 +
 +  for (i = 0; i < m_workstationNb; i++) {
 +    for (j = 0; j < m_workstationNb; j++) {
 +      xbt_dynar_t route=NULL;
 +
 +      if (p_communicationAmount[i * m_workstationNb + j] > 0) {
 +        double lat = 0.0;
 +        routing_platf->getRouteAndLatency(dynamic_cast<WorkstationL07Ptr>(
 +                                           static_cast<ResourcePtr>(((void**)p_workstationList)[i]))->p_netElm,
 +                                          dynamic_cast<WorkstationL07Ptr>(
 +                                           static_cast<ResourcePtr>(((void**)p_workstationList)[j]))->p_netElm,
 +                                                        &route, &lat);
 +
 +        lat_current = MAX(lat_current, lat * p_communicationAmount[i * m_workstationNb + j]);
 +      }
 +    }
 +  }
 +  lat_bound = sg_tcp_gamma / (2.0 * lat_current);
 +  XBT_DEBUG("action (%p) : lat_bound = %g", this, lat_bound);
 +  if ((m_latency == 0.0) && (m_suspended == 0)) {
 +    if (m_rate < 0)
 +      lmm_update_variable_bound(ptask_maxmin_system, p_variable, lat_bound);
 +    else
 +      lmm_update_variable_bound(ptask_maxmin_system, p_variable, min(m_rate, lat_bound));
 +  }
 +}
 +
 +int WorkstationL07ActionLmm::unref()
 +{
 +  m_refcount--;
 +  if (!m_refcount) {
 +    xbt_swag_remove(static_cast<ActionPtr>(this), p_stateSet);
 +    if (p_variable)
 +      lmm_variable_free(ptask_maxmin_system, p_variable);
 +    delete this;
 +    return 1;
 +  }
 +  return 0;
 +}
 +
 +void WorkstationL07ActionLmm::cancel()
 +{
 +  setState(SURF_ACTION_FAILED);
 +  return;
 +}
 +
 +void WorkstationL07ActionLmm::suspend()
 +{
 +  XBT_IN("(%p))", this);
 +  if (m_suspended != 2) {
 +    m_suspended = 1;
 +    lmm_update_variable_weight(ptask_maxmin_system, p_variable, 0.0);
 +  }
 +  XBT_OUT();
 +}
 +
 +void WorkstationL07ActionLmm::resume()
 +{
 +  XBT_IN("(%p)", this);
 +  if (m_suspended != 2) {
 +    lmm_update_variable_weight(ptask_maxmin_system, p_variable, 1.0);
 +    m_suspended = 0;
 +  }
 +  XBT_OUT();
 +}
 +
 +bool WorkstationL07ActionLmm::isSuspended()
 +{
 +  return m_suspended == 1;
 +}
 +
 +void WorkstationL07ActionLmm::setMaxDuration(double duration)
 +{                               /* FIXME: should inherit */
 +  XBT_IN("(%p,%g)", this, duration);
 +  m_maxDuration = duration;
 +  XBT_OUT();
 +}
 +
 +void WorkstationL07ActionLmm::setPriority(double priority)
 +{                               /* FIXME: should inherit */
 +  XBT_IN("(%p,%g)", this, priority);
 +  m_priority = priority;
 +  XBT_OUT();
 +}
 +
 +double WorkstationL07ActionLmm::getRemains()
 +{
 +  XBT_IN("(%p)", this);
 +  XBT_OUT();
 +  return m_remains;
 +}
 +
 +
 +
 +
 +
 +
 +
 +
 +
 +static void ptask_finalize(void)
 +{
 +  xbt_dict_free(&ptask_parallel_task_link_set);
 +
 +  delete surf_workstation_model;
 +  surf_workstation_model = NULL;
 +  delete surf_network_model;
 +  surf_network_model = NULL;
 +
 +  ptask_host_count = 0;
 +
 +  if (ptask_maxmin_system) {
 +    lmm_system_free(ptask_maxmin_system);
 +    ptask_maxmin_system = NULL;
 +  }
 +}
 +
 +/**************************************/
 +/******* Resource Private    **********/
 +/**************************************/
 +
 +
 +
 +
 +
 +
 +
 +
 +
 +
 +
 +
 +
 +
 +
 +
 +/**************************************/
 +/*** Resource Creation & Destruction **/
 +/**************************************/
 +
 +static void ptask_parse_workstation_init(sg_platf_host_cbarg_t host)
 +{
++  double power_peak = xbt_dynar_get_as(host->power_peak, host->pstate, double);
++  //cpu->power_peak = power_peak;
++  xbt_dynar_free(&(host->power_peak));  /* kill memory leak */
 +  static_cast<WorkstationL07ModelPtr>(surf_workstation_model)->createResource(
 +      host->id,
-       static_cast<CpuL07ModelPtr>(surf_cpu_model)->createResource(
++      power_peak,
 +      host->power_scale,
 +      host->power_trace,
 +      host->initial_state,
 +      host->state_trace,
 +      host->properties);
 +}
 +
 +static void ptask_parse_cpu_init(sg_platf_host_cbarg_t host)
 +{
-       host->power_peak,
++  double power_peak = xbt_dynar_get_as(host->power_peak, host->pstate, double);
++  static_cast<CpuL07ModelPtr>(surf_cpu_model)->createResource(
 +      host->id,
++      power_peak,
 +      host->power_scale,
 +      host->power_trace,
 +      host->initial_state,
 +      host->state_trace,
 +      host->properties);
 +}
 +
 +
 +
 +static void ptask_parse_link_init(sg_platf_link_cbarg_t link)
 +{
 +  if (link->policy == SURF_LINK_FULLDUPLEX) {
 +    char *link_id;
 +    link_id = bprintf("%s_UP", link->id);
 +    static_cast<NetworkL07ModelPtr>(surf_network_model)->createResource(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);
 +    static_cast<NetworkL07ModelPtr>(surf_network_model)->createResource(link_id,
 +                               link->bandwidth,
 +                               link->bandwidth_trace,
 +                               link->latency,
 +                               link->latency_trace,
 +                               link->state,
 +                               link->state_trace,
 +                               link->policy,
 +                               NULL); /* FIXME: We need to deep copy the
 +                                       * properties or we won't be able to free
 +                                       * it */
 +    xbt_free(link_id);
 +  } else {
 +        static_cast<NetworkL07ModelPtr>(surf_network_model)->createResource(link->id,
 +                               link->bandwidth,
 +                               link->bandwidth_trace,
 +                               link->latency,
 +                               link->latency_trace,
 +                               link->state,
 +                               link->state_trace,
 +                               link->policy,
 +                               link->properties);
 +  }
 +
 +  current_property_set = NULL;
 +}
 +
 +static void ptask_add_traces(){
 +  static_cast<WorkstationL07ModelPtr>(surf_workstation_model)->addTraces();
 +}
 +
 +static void ptask_define_callbacks()
 +{
 +  sg_platf_host_add_cb(ptask_parse_cpu_init);
 +  sg_platf_host_add_cb(ptask_parse_workstation_init);
 +  sg_platf_link_add_cb(ptask_parse_link_init);
 +  sg_platf_postparse_add_cb(ptask_add_traces);
 +}
 +
 +/**************************************/
 +/*************** Generic **************/
 +/**************************************/
 +void surf_workstation_model_init_ptask_L07(void)
 +{
 +  XBT_INFO("surf_workstation_model_init_ptask_L07");
 +  xbt_assert(!surf_cpu_model, "CPU model type already defined");
 +  xbt_assert(!surf_network_model, "network model type already defined");
 +  ptask_define_callbacks();
 +  surf_workstation_model = new WorkstationL07Model();
 +  ModelPtr model = static_cast<ModelPtr>(surf_workstation_model);
 +  xbt_dynar_push(model_list, &model);
 +}
index ded3df2,0000000..0cd7713
mode 100644,000000..100644
--- /dev/null
@@@ -1,173 -1,0 +1,184 @@@
 +#include "workstation.hpp"
 +
 +#ifndef WORKSTATION_L07_HPP_
 +#define WORKSTATION_L07_HPP_
 +
 +/***********
 + * Classes *
 + ***********/
 +
 +class WorkstationL07Model;
 +typedef WorkstationL07Model *WorkstationL07ModelPtr;
 +
 +class CpuL07Model;
 +typedef CpuL07Model *CpuL07ModelPtr;
 +
 +class NetworkL07Model;
 +typedef NetworkL07Model *NetworkL07ModelPtr;
 +
 +class WorkstationL07;
 +typedef WorkstationL07 *WorkstationL07Ptr;
 +
 +class CpuL07;
 +typedef CpuL07 *CpuL07Ptr;
 +
 +class LinkL07;
 +typedef LinkL07 *LinkL07Ptr;
 +
 +class WorkstationL07ActionLmm;
 +typedef WorkstationL07ActionLmm *WorkstationL07ActionLmmPtr;
 +
 +/*FIXME:class WorkstationActionLmm;
 +typedef WorkstationActionLmm *WorkstationActionLmmPtr;*/
 +
 +/*********
 + * Tools *
 + *********/
 +
 +/*********
 + * Model *
 + *********/
 +class WorkstationL07Model : public WorkstationModel {
 +public:
 +  WorkstationL07Model();
 +  ~WorkstationL07Model();
 +
 +  double shareResources(double now);
 +  void updateActionsState(double now, double delta);
 +  ResourcePtr createResource(const char *name, double power_scale,
 +                                 double power_initial,
 +                                 tmgr_trace_t power_trace,
 +                                 e_surf_resource_state_t state_initial,
 +                                 tmgr_trace_t state_trace,
 +                                 xbt_dict_t cpu_properties);
 +  ActionPtr executeParallelTask(int workstation_nb,
 +                                        void **workstation_list,
 +                                        double *computation_amount,
 +                                        double *communication_amount,
 +                                        double rate);
 +  xbt_dynar_t getRoute(WorkstationCLM03Ptr src, WorkstationCLM03Ptr dst);
 +  ActionPtr communicate(WorkstationCLM03Ptr src, WorkstationCLM03Ptr dst, double size, double rate);
 +  void addTraces();
 +  CpuL07ModelPtr p_cpuModel;
 +  NetworkL07ModelPtr p_networkModel;
 +};
 +
 +class CpuL07Model : public CpuModel {
 +public:
 +  CpuL07Model() : CpuModel("cpuL07") {};
 +  ~CpuL07Model() {surf_cpu_model = NULL;};
 +  ResourcePtr createResource(const char *name, double power_scale,
 +                                 double power_initial,
 +                                 tmgr_trace_t power_trace,
 +                                 e_surf_resource_state_t state_initial,
 +                                 tmgr_trace_t state_trace,
 +                                 xbt_dict_t cpu_properties);
 +  void addTraces() {DIE_IMPOSSIBLE;};
 +  WorkstationL07ModelPtr p_workstationModel;
 +};
 +
 +class NetworkL07Model : public NetworkCm02Model {
 +public:
 +  NetworkL07Model() : NetworkCm02Model(0) {};
 +  ~NetworkL07Model() {surf_network_model = NULL;};
 +  ResourcePtr createResource(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);
 +
 +  xbt_dynar_t getRoute(WorkstationCLM03Ptr src, WorkstationCLM03Ptr dst) {DIE_IMPOSSIBLE;};
 +  ActionPtr communicate(RoutingEdgePtr src, RoutingEdgePtr dst, double size, double rate) {DIE_IMPOSSIBLE;};
 +  void addTraces() {DIE_IMPOSSIBLE;};
 +  WorkstationL07ModelPtr p_workstationModel;
 +};
 +
 +/************
 + * Resource *
 + ************/
 +
 +class WorkstationL07 : public WorkstationCLM03Lmm {
 +public:
 +  WorkstationL07(WorkstationModelPtr model, const char* name, xbt_dict_t props, RoutingEdgePtr netElm, CpuPtr cpu);
 +  //bool isUsed();
 +  bool isUsed() {DIE_IMPOSSIBLE;};
 +  void updateState(tmgr_trace_event_t event_type, double value, double date) {DIE_IMPOSSIBLE;};
 +  ActionPtr execute(double size);
 +  ActionPtr sleep(double duration);
 +  e_surf_resource_state_t getState();
++  double getPowerPeakAt(int pstate_index);
++  int getNbPstates();
++  void setPowerPeakAt(int pstate_index);
++  double getConsumedEnergy();
 +};
 +
 +class CpuL07 : public CpuLmm {
 +public:
 +  CpuL07(CpuL07ModelPtr model, const char* name, xbt_dict_t properties);
 +  bool isUsed();
 +  //bool isUsed() {DIE_IMPOSSIBLE;};
 +  void updateState(tmgr_trace_event_t event_type, double value, double date);
 +  e_surf_resource_state_t getState();
 +  double getSpeed(double load);
 +  double getAvailableSpeed();
 +  ActionPtr execute(double size) {DIE_IMPOSSIBLE;};
 +  ActionPtr sleep(double duration) {DIE_IMPOSSIBLE;};
++
++  double getCurrentPowerPeak() {};
++  double getPowerPeakAt(int pstate_index) {};
++  int getNbPstates() {};
++  void setPowerPeakAt(int pstate_index) {};
++  double getConsumedEnergy() {};
++
 +  double m_powerCurrent;
 +};
 +
 +class LinkL07 : public NetworkCm02LinkLmm {
 +public:
 +  LinkL07(NetworkL07ModelPtr model, const char* name, xbt_dict_t props);
 +  bool isUsed();
 +  void updateState(tmgr_trace_event_t event_type, double value, double date);
 +  double getBandwidth();
 +  double getLatency();
 +  bool isShared();
 +
 +  double m_latCurrent;
 +  tmgr_trace_event_t p_latEvent;
 +  double m_bwCurrent;
 +  tmgr_trace_event_t p_bwEvent;
 +};
 +
 +/**********
 + * Action *
 + **********/
 +class WorkstationL07ActionLmm : public WorkstationActionLmm {
 +public:
 +  WorkstationL07ActionLmm(ModelPtr model, double cost, bool failed)
 +  : Action(model, cost, failed), WorkstationActionLmm(model, cost, failed) {};
 + ~WorkstationL07ActionLmm();
 +
 +  void updateBound();
 +
 +  int unref();
 +  void cancel();
 +  void suspend();
 +  void resume();
 +  bool isSuspended();
 +  void setMaxDuration(double duration);
 +  void setPriority(double priority);
 +  double getRemains();
 +
 +  int m_workstationNb;
 +  WorkstationCLM03Ptr *p_workstationList;
 +  double *p_computationAmount;
 +  double *p_communicationAmount;
 +  double m_latency;
 +  double m_rate;
 +};
 +
 +#endif /* WORKSTATION_L07_HPP_ */
diff --combined src/xbt/log.c
@@@ -1,6 -1,6 +1,6 @@@
  /* log - a generic logging facility in the spirit of log4j                  */
  
- /* Copyright (c) 2004-2011. The SimGrid Team.
+ /* Copyright (c) 2004-2013. The SimGrid Team.
   * All rights reserved.                                                     */
  
  /* This program is free software; you can redistribute it and/or modify it
@@@ -681,6 -681,7 +681,6 @@@ static void xbt_log_connect_categories(
    XBT_LOG_CONNECT(surf_lagrange_dichotomy);
    XBT_LOG_CONNECT(surf_maxmin);
    XBT_LOG_CONNECT(surf_network);
 -  XBT_LOG_CONNECT(surf_new_model);
  #ifdef HAVE_GTNETS
    XBT_LOG_CONNECT(surf_network_gtnets);
    XBT_LOG_CONNECT(surf_network_gtnets_interface);
@@@ -1099,7 -1100,12 +1099,12 @@@ static xbt_log_setting_t _xbt_log_parse
          break;
        }
      }
-     if (i < xbt_log_priority_infinite) {
+     if(i<XBT_LOG_STATIC_THRESHOLD){
+      THROWF(arg_error, 0,
+              "Priority: %s is above allowed priority : %s (for debug and trace levels, recompile SimGrid with -Denable_debug=ON)",
+              eq + 1, xbt_log_priority_names[XBT_LOG_STATIC_THRESHOLD]);
+     }else if (i < xbt_log_priority_infinite) {
        set->thresh = (e_xbt_log_priority_t) i;
      } else {
        THROWF(arg_error, 0,
diff --combined src/xbt/swag.c
@@@ -1,4 -1,4 +1,4 @@@
- /* Copyright (c) 2004, 2005, 2006, 2007, 2008, 2009, 2010. The SimGrid Team.
+ /* Copyright (c) 2004-2012. The SimGrid Team.
   * All rights reserved.                                                     */
  
  /* This program is free software; you can redistribute it and/or modify it
@@@ -14,6 -14,7 +14,6 @@@
  #include "xbt/log.h"
  #include "xbt/swag.h"
  
 -
  /** Creates a new swag.
   * \param offset where the hookup is located in the structure
   * \see xbt_swag_offset
@@@ -1,4 -1,4 +1,4 @@@
- /* Copyright (c) 2008, 2009, 2010. The SimGrid Team.
+ /* Copyright (c) 2008-2013. The SimGrid Team.
   * All rights reserved.                                                     */
  
  /* This program is free software; you can redistribute it and/or modify it
@@@ -104,7 -104,12 +104,12 @@@ int main(int argc, char **argv
    const SD_link_t *links;
    xbt_os_timer_t parse_time = xbt_os_timer_new();
  
+ #ifdef _XBT_WIN32
+   setbuf(stderr, NULL);
+   setbuf(stdout, NULL);
+ #else
    setvbuf(stdout, NULL, _IOLBF, 0);
+ #endif
  
    SD_init(&argc, argv);
  
  
      // Routers
      xbt_lib_foreach(as_router_lib, cursor_src, key, value1) {
 -      if(((sg_routing_edge_t)xbt_lib_get_or_null(as_router_lib, key,
 -          ROUTING_ASR_LEVEL))->rc_type == SURF_NETWORK_ELEMENT_ROUTER)
 +      if(surf_routing_edge_get_rc_type(xbt_lib_get_or_null(as_router_lib, key,
 +          ROUTING_ASR_LEVEL)) == SURF_NETWORK_ELEMENT_ROUTER)
        {
          printf("  <router id=\"%s\"/>\n",key);
        }
          {
            void *link = xbt_dynar_get_as(route,i,void *);
  
 -          char *link_name = xbt_strdup(((surf_resource_t)link)->name);
 +          char *link_name = xbt_strdup(surf_resource_name(link));
            printf("<%s id=\"%s\"/>",link_ctn,link_name);
            free(link_name);
          }
            {
              void *link = xbt_dynar_get_as(route,i,void *);
  
 -            char *link_name = xbt_strdup(((surf_resource_t)link)->name);
 +            char *link_name = xbt_strdup(surf_resource_name(link));
              printf("<%s id=\"%s\"/>",link_ctn,link_name);
              free(link_name);
            }
              {
                void *link = xbt_dynar_get_as(route,i,void *);
  
 -              char *link_name = xbt_strdup(((surf_resource_t)link)->name);
 +              char *link_name = xbt_strdup(surf_resource_name(link));
                printf("<%s id=\"%s\"/>",link_ctn,link_name);
                free(link_name);
              }
            {
              void *link = xbt_dynar_get_as(route,i,void *);
  
 -            char *link_name = xbt_strdup(((surf_resource_t)link)->name);
 +            char *link_name = xbt_strdup(surf_resource_name(link));
              printf("<%s id=\"%s\"/>",link_ctn,link_name);
              free(link_name);
            }
@@@ -1,6 -1,6 +1,6 @@@
  /* A few basic tests for the surf library                                   */
  
- /* Copyright (c) 2004, 2005, 2006, 2007, 2008, 2009, 2010. The SimGrid Team.
+ /* Copyright (c) 2004-2012. The SimGrid Team.
   * All rights reserved.                                                     */
  
  /* This program is free software; you can redistribute it and/or modify it
@@@ -63,18 -63,18 +63,18 @@@ void test(char *platform
    cpuB = surf_cpu_resource_by_name("Cpu B");
  
    /* Let's check that those two processors exist */
 -  XBT_DEBUG("%s : %p", surf_resource_name(cpuA), cpuA);
 -  XBT_DEBUG("%s : %p", surf_resource_name(cpuB), cpuB);
 +  XBT_DEBUG("%s : %p", surf_resource_name(surf_cpu_resource_priv(cpuA)), cpuA);
 +  XBT_DEBUG("%s : %p", surf_resource_name(surf_cpu_resource_priv(cpuB)), cpuB);
  
    /* Let's do something on it */
 -  actionA = surf_cpu_model->extension.cpu.execute(cpuA, 1000.0);
 -  actionB = surf_cpu_model->extension.cpu.execute(cpuB, 1000.0);
 -  actionC = surf_cpu_model->extension.cpu.sleep(cpuB, 7.32);
 +  actionA = surf_cpu_execute(cpuA, 1000.0);
 +  actionB = surf_cpu_execute(cpuB, 1000.0);
 +  actionC = surf_cpu_sleep(cpuB, 7.32);
  
    /* Use whatever calling style you want... */
 -  stateActionA = surf_cpu_model->action_state_get(actionA);     /* When you know actionA model type */
 -  stateActionB = actionB->model_type->action_state_get(actionB);        /* If you're unsure about it's model type */
 -  stateActionC = surf_cpu_model->action_state_get(actionC);     /* When you know actionA model type */
 +  stateActionA = surf_action_get_state(actionA);     /* When you know actionA model type */
 +  stateActionB = surf_action_get_state(actionB);        /* If you're unsure about it's model type */
 +  stateActionC = surf_action_get_state(actionC);     /* When you know actionA model type */
  
    /* And just look at the state of these tasks */
    XBT_DEBUG("actionA : %p (%s)", actionA, string_action(stateActionA));
    cardB = sg_routing_edge_by_name_or_null("Cpu B");
  
    /* Let's check that those two processors exist */
 -  XBT_DEBUG("%s : %p", surf_resource_name(cardA), cardA);
 -  XBT_DEBUG("%s : %p", surf_resource_name(cardB), cardB);
 +  XBT_DEBUG("%s : %p", surf_routing_edge_name(cardA), cardA);
 +  XBT_DEBUG("%s : %p", surf_routing_edge_name(cardB), cardB);
  
    /* Let's do something on it */
 -  surf_network_model->extension.network.communicate(cardA, cardB,
 -                                                    150.0, -1.0);
 +  surf_network_model_communicate(surf_network_model, cardA, cardB, 150.0, -1.0);
  
    surf_solve(-1.0);                 /* Takes traces into account. Returns 0.0 */
    do {
      XBT_DEBUG("Next Event : %g", now);
      XBT_DEBUG("\t CPU actions");
      while ((action =
 -            xbt_swag_extract(surf_cpu_model->states.failed_action_set))) {
 +            xbt_swag_extract(surf_model_failed_action_set((surf_model_t)surf_cpu_model)))) {
        XBT_DEBUG("\t * Failed : %p", action);
 -      action->model_type->action_unref(action);
 +      surf_action_unref(action);
      }
      while ((action =
 -            xbt_swag_extract(surf_cpu_model->states.done_action_set))) {
 +            xbt_swag_extract(surf_model_done_action_set((surf_model_t)surf_cpu_model)))) {
        XBT_DEBUG("\t * Done : %p", action);
 -      action->model_type->action_unref(action);
 +      surf_action_unref(action);
      }
      XBT_DEBUG("\t Network actions");
      while ((action =
 -            xbt_swag_extract(surf_network_model->states.
 -                             failed_action_set))) {
 +            xbt_swag_extract(surf_model_failed_action_set((surf_model_t)surf_network_model)))) {
        XBT_DEBUG("\t * Failed : %p", action);
 -      action->model_type->action_unref(action);
 +      surf_action_unref(action);
      }
      while ((action =
 -            xbt_swag_extract(surf_network_model->states.
 -                             done_action_set))) {
 +            xbt_swag_extract(surf_model_done_action_set((surf_model_t)surf_network_model)))) {
        XBT_DEBUG("\t * Done : %p", action);
 -      action->model_type->action_unref(action);
 +      surf_action_unref(action);
      }
  
 -  } while ((xbt_swag_size(surf_network_model->states.running_action_set) ||
 -            xbt_swag_size(surf_cpu_model->states.running_action_set)) &&
 +  } while ((xbt_swag_size(surf_model_running_action_set((surf_model_t)surf_network_model)) ||
 +            xbt_swag_size(surf_model_running_action_set((surf_model_t)surf_cpu_model))) &&
             surf_solve(-1.0) >= 0.0);
  
    XBT_DEBUG("Simulation Terminated");
@@@ -1,6 -1,6 +1,6 @@@
  /* A few basic tests for the surf library                                   */
  
- /* Copyright (c) 2004, 2005, 2006, 2007, 2008, 2009, 2010. The SimGrid Team.
+ /* Copyright (c) 2004-2012. The SimGrid Team.
   * All rights reserved.                                                     */
  
  /* This program is free software; you can redistribute it and/or modify it
@@@ -62,11 -62,12 +62,11 @@@ void test(char *platform
    XBT_DEBUG("%s : %p", surf_resource_name(workstationB), workstationB);
  
    /* Let's do something on it */
 -  surf_workstation_model->extension.workstation.execute(workstationA, 1000.0);
 -  surf_workstation_model->extension.workstation.execute(workstationB, 1000.0);
 -      surf_workstation_model->extension.workstation.sleep(workstationB, 7.32);
 +  surf_workstation_execute(workstationA, 1000.0);
 +  surf_workstation_execute(workstationB, 1000.0);
 +  surf_workstation_sleep(workstationB, 7.32);
  
 -  surf_workstation_model->extension.workstation.
 -      communicate(workstationA, workstationB, 150.0, -1.0);
 +  surf_workstation_model_communicate(surf_workstation_model, workstationA, workstationB, 150.0, -1.0);
  
    surf_solve(-1.0);                 /* Takes traces into account. Returns 0.0 */
    do {
      XBT_DEBUG("Next Event : %g", now);
  
      xbt_dynar_foreach(model_list, iter, model) {
 -      XBT_DEBUG("\t %s actions", model->name);
 -      while ((action = xbt_swag_extract(model->states.failed_action_set))) {
 +      XBT_DEBUG("\t %s actions", surf_model_name(model));
 +      while ((action = xbt_swag_extract(surf_model_failed_action_set((surf_model_t)model)))) {
          XBT_DEBUG("\t * Failed : %p", action);
 -        model->action_unref(action);
 +        surf_action_unref(action);
        }
 -      while ((action = xbt_swag_extract(model->states.done_action_set))) {
 +      while ((action = xbt_swag_extract(surf_model_done_action_set((surf_model_t)model)))) {
          XBT_DEBUG("\t * Done : %p", action);
 -        model->action_unref(action);
 +        surf_action_unref(action);
        }
 -      if (xbt_swag_size(model->states.running_action_set)) {
 -        XBT_DEBUG("running %s", model->name);
 +      if (xbt_swag_size(surf_model_running_action_set((surf_model_t)model))) {
 +        XBT_DEBUG("running %s", surf_model_name(model));
          running = 1;
        }
      }