Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix NS3 and latency bound tracking
authorPaul Bédaride <paul.bedaride@gmail.com>
Wed, 12 Feb 2014 09:27:37 +0000 (10:27 +0100)
committerPaul Bédaride <paul.bedaride@gmail.com>
Wed, 12 Feb 2014 09:53:04 +0000 (10:53 +0100)
15 files changed:
buildtools/Cmake/DefinePackages.cmake
buildtools/Cmake/MakeLib.cmake
buildtools/Cmake/Modules/FindNS3.cmake
examples/msg/ns3/ns3.tesh
src/include/surf/surf.h
src/simix/smx_network.c
src/surf/network_interface.hpp
src/surf/network_ns3.cpp [new file with mode: 0644]
src/surf/network_ns3.hpp [new file with mode: 0644]
src/surf/ns3/my-point-to-point-helper.cc
src/surf/ns3/ns3_interface.cc
src/surf/surf_c_bindings.cpp
src/surf/surf_interface.hpp
src/surf/vm_workstation_hl13.cpp
src/surf/workstation_clm03.cpp

index b3a3ce2..fd3a7a4 100644 (file)
@@ -57,7 +57,7 @@ set(EXTRA_DIST
   src/surf/maxmin_private.hpp
   src/surf/network_interface.hpp
   src/surf/network_gtnets.hpp
   src/surf/maxmin_private.hpp
   src/surf/network_interface.hpp
   src/surf/network_gtnets.hpp
-  src/surf/network_ns3_private.h
+  src/surf/network_ns3.hpp
   src/surf/network_cm02.hpp
   src/surf/network_smpi.hpp
   src/surf/network_constant.hpp
   src/surf/network_cm02.hpp
   src/surf/network_smpi.hpp
   src/surf/network_constant.hpp
@@ -300,7 +300,7 @@ set(GTNETS_SRC
   )
 
 set(NS3_SRC
   )
 
 set(NS3_SRC
-  src/surf/network_ns3.c
+  src/surf/network_ns3.cpp
   src/surf/ns3/my-point-to-point-helper.cc
   src/surf/ns3/ns3_interface.cc
   src/surf/ns3/ns3_simulator.cc
   src/surf/ns3/my-point-to-point-helper.cc
   src/surf/ns3/ns3_interface.cc
   src/surf/ns3/ns3_simulator.cc
index 95f7576..1e21137 100644 (file)
@@ -91,12 +91,12 @@ if(MMALLOC_WANT_OVERRIDE_LEGACY AND HAVE_GNU_LD)
 endif()
 
 if(HAVE_NS3)
 endif()
 
 if(HAVE_NS3)
-  if(${NS3_VERSION} EQUAL 310)
+  if(${NS3_VERSION_MINOR} EQUAL 10)
     SET(SIMGRID_DEP "${SIMGRID_DEP} -lns3")
     set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_NS3_3_10")
     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_NS3_3_10")
   else()
     SET(SIMGRID_DEP "${SIMGRID_DEP} -lns3")
     set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_NS3_3_10")
     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_NS3_3_10")
   else()
-    SET(SIMGRID_DEP "${SIMGRID_DEP} -lns3-core -lns3-csma -lns3-point-to-point -lns3-internet -lns3-applications")
+    SET(SIMGRID_DEP "${SIMGRID_DEP} -lns3.${NS3_VERSION_MINOR}-core -lns3.${NS3_VERSION_MINOR}-csma -lns3.${NS3_VERSION_MINOR}-point-to-point -lns3.${NS3_VERSION_MINOR}-internet -lns3.${NS3_VERSION_MINOR}-applications")
   endif()
 endif()
 
   endif()
 endif()
 
index 8bb4c0c..2e0afbd 100644 (file)
@@ -13,7 +13,7 @@ find_library(HAVE_NS3_LIB
   )
 
 find_library(HAVE_NS3_CORE_LIB
   )
 
 find_library(HAVE_NS3_CORE_LIB
-  NAME ns3-core
+  NAME ns3-core ns3.14-core ns3.17-core
   PATH_SUFFIXES lib64 lib ns3/lib
   PATHS
   ${ns3_path}
   PATH_SUFFIXES lib64 lib ns3/lib
   PATHS
   ${ns3_path}
@@ -21,7 +21,7 @@ find_library(HAVE_NS3_CORE_LIB
 
 find_path(HAVE_CORE_MODULE_H
   NAME ns3/core-module.h
 
 find_path(HAVE_CORE_MODULE_H
   NAME ns3/core-module.h
-  PATH_SUFFIXES include ns3/include include/ns3.14.1
+  PATH_SUFFIXES include ns3/include include/ns3.14.1 include/ns3.17
   PATHS
   ${ns3_path}
   )
   PATHS
   ${ns3_path}
   )
@@ -56,14 +56,14 @@ if(HAVE_CORE_MODULE_H)
   if(HAVE_NS3_LIB)
     message(STATUS "Warning: NS-3 version <= 3.10")
     set(HAVE_NS3 1)
   if(HAVE_NS3_LIB)
     message(STATUS "Warning: NS-3 version <= 3.10")
     set(HAVE_NS3 1)
-    set(NS3_VERSION 310)
-    string(REPLACE "/libns3.${LIB_EXE}" ""  HAVE_NS3_LIB "${HAVE_NS3_LIB}")
+    set(NS3_VERSION_MINOR 10)
+    string(REPLACE "/libns3.${LIB_EXE}" "" HAVE_NS3_LIB "${HAVE_NS3_LIB}")
   endif()
   if(HAVE_NS3_CORE_LIB)
     message(STATUS "NS-3 version > 3.10")
   endif()
   if(HAVE_NS3_CORE_LIB)
     message(STATUS "NS-3 version > 3.10")
+    string(REGEX REPLACE ".*ns3.([0-9]+)-core.*" "\\1" NS3_VERSION_MINOR "${HAVE_NS3_CORE_LIB}")
     set(HAVE_NS3 1)
     set(HAVE_NS3 1)
-    set(NS3_VERSION 312)
-    string(REPLACE "/libns3-core.${LIB_EXE}" ""  HAVE_NS3_LIB "${HAVE_NS3_CORE_LIB}")
+    string(REPLACE "/libns3-core.${LIB_EXE}" "" HAVE_NS3_LIB "${HAVE_NS3_CORE_LIB}")
   endif()
 endif()
 
   endif()
 endif()
 
@@ -84,6 +84,7 @@ if(HAVE_NS3)
     endif()
 
     SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}-I${HAVE_CORE_MODULE_H} -L${HAVE_NS3_LIB} ")
     endif()
 
     SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}-I${HAVE_CORE_MODULE_H} -L${HAVE_NS3_LIB} ")
+    message(STATUS "TEST: ${CMAKE_CXX_FLAGS}")
   endif()
 else()
   message(STATUS "Warning: To use NS-3 Please install ns3 at least version 3.10 (http://www.nsnam.org/releases/)")
   endif()
 else()
   message(STATUS "Warning: To use NS-3 Please install ns3 at least version 3.10 (http://www.nsnam.org/releases/)")
index cb26e47..52094b2 100644 (file)
@@ -29,11 +29,11 @@ p One cluster
 $ ns3/ns3 ${srcdir:=.}/examples/platforms/cluster.xml ${srcdir:=.}/examples/msg/ns3/One_cluster-d.xml --cfg=network/model:NS3
 > [0.000000] [xbt_cfg/INFO] Configuration change: Set 'network/model' to 'NS3'
 > [0.000000] [surf_config/INFO] Switching workstation model to compound since you changed the network and/or cpu model(s)
 $ ns3/ns3 ${srcdir:=.}/examples/platforms/cluster.xml ${srcdir:=.}/examples/msg/ns3/One_cluster-d.xml --cfg=network/model:NS3
 > [0.000000] [xbt_cfg/INFO] Configuration change: Set 'network/model' to 'NS3'
 > [0.000000] [surf_config/INFO] Switching workstation model to compound since you changed the network and/or cpu model(s)
-> [c-6.me:slave:(2) 0.006614] [msg_test/INFO] FLOW[1] : Receive 100 bytes from c-2.me to c-6.me
+> [c-6.me:slave:(2) 0.006755] [msg_test/INFO] FLOW[1] : Receive 100 bytes from c-2.me to c-6.me
 
 p Two clusters
 
 $ ns3/ns3 ${srcdir:=.}/examples/platforms/clusters_routing_full.xml ${srcdir:=.}/examples/msg/ns3/Two_clusters-d.xml --cfg=network/model:NS3
 > [0.000000] [xbt_cfg/INFO] Configuration change: Set 'network/model' to 'NS3'
 > [0.000000] [surf_config/INFO] Switching workstation model to compound since you changed the network and/or cpu model(s)
 
 p Two clusters
 
 $ ns3/ns3 ${srcdir:=.}/examples/platforms/clusters_routing_full.xml ${srcdir:=.}/examples/msg/ns3/Two_clusters-d.xml --cfg=network/model:NS3
 > [0.000000] [xbt_cfg/INFO] Configuration change: Set 'network/model' to 'NS3'
 > [0.000000] [surf_config/INFO] Switching workstation model to compound since you changed the network and/or cpu model(s)
-> [c-16.me:slave:(2) 0.012453] [msg_test/INFO] FLOW[1] : Receive 100 bytes from c-3.me to c-16.me
+> [c-16.me:slave:(2) 0.012729] [msg_test/INFO] FLOW[1] : Receive 100 bytes from c-3.me to c-16.me
index 5a787fa..2a230ce 100644 (file)
@@ -188,6 +188,7 @@ typedef enum {
 /***************************/
 /* Generic model object */
 /***************************/
 /***************************/
 /* Generic model object */
 /***************************/
+
 //FIXME:REMOVE typedef struct s_routing_platf s_routing_platf_t, *routing_platf_t;
 XBT_PUBLIC_DATA(routing_platf_t) routing_platf;
 
 //FIXME:REMOVE typedef struct s_routing_platf s_routing_platf_t, *routing_platf_t;
 XBT_PUBLIC_DATA(routing_platf_t) routing_platf;
 
@@ -875,6 +876,14 @@ XBT_PUBLIC(void) surf_cpu_action_set_affinity(surf_action_t action, surf_resourc
  */
 XBT_PUBLIC(void) surf_cpu_action_set_bound(surf_action_t action, double bound);
 
  */
 XBT_PUBLIC(void) surf_cpu_action_set_bound(surf_action_t action, double bound);
 
+/**
+ * @brief [brief description]
+ * @details [long description]
+ *
+ * @param action The surf network action
+ */
+XBT_PUBLIC(double) surf_network_action_get_latency_limited(surf_action_t action);
+
 /**
  * @brief Get the file associated to a storage action
  * 
 /**
  * @brief Get the file associated to a storage action
  * 
index ab44443..a30ee03 100644 (file)
@@ -1112,7 +1112,7 @@ XBT_INLINE int SIMIX_comm_is_latency_bounded(smx_action_t action)
   }
   if (action->comm.surf_comm){
     XBT_DEBUG("Getting latency limited for surf_action (%p)", action->comm.surf_comm);
   }
   if (action->comm.surf_comm){
     XBT_DEBUG("Getting latency limited for surf_action (%p)", action->comm.surf_comm);
-    action->latency_limited = surf_workstation_model->get_latency_limited(action->comm.surf_comm);
+    action->latency_limited = surf_network_action_get_latency_limited(action->comm.surf_comm);
     XBT_DEBUG("Action limited is %d", action->latency_limited);
   }
   return action->latency_limited;
     XBT_DEBUG("Action limited is %d", action->latency_limited);
   }
   return action->latency_limited;
index b184770..994991b 100644 (file)
@@ -293,6 +293,15 @@ public:
 
   void setState(e_surf_action_state_t state);
 
 
   void setState(e_surf_action_state_t state);
 
+#ifdef HAVE_LATENCY_BOUND_TRACKING
+  /**
+   * @brief Check if the action is limited by latency.
+   *
+   * @return 1 if action is limited by latency, 0 otherwise
+   */
+  virtual int getLatencyLimited() {return m_latencyLimited;}
+#endif
+
   double m_latency;
   double m_latCurrent;
   double m_weight;
   double m_latency;
   double m_latCurrent;
   double m_weight;
diff --git a/src/surf/network_ns3.cpp b/src/surf/network_ns3.cpp
new file mode 100644 (file)
index 0000000..4fecb0f
--- /dev/null
@@ -0,0 +1,494 @@
+/* Copyright (c) 2007-2013. The SimGrid Team.
+ *
+ * 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 "network_ns3.hpp"
+#include "surf_private.h"
+#include "simgrid/sg_config.h"
+
+XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_network_ns3, surf,
+                                "Logging specific to the SURF network NS3 module");
+
+extern xbt_lib_t host_lib;
+extern xbt_lib_t link_lib;
+extern xbt_lib_t as_router_lib;
+
+extern xbt_dict_t dict_socket;
+
+xbt_dynar_t IPV4addr;
+static double time_to_next_flow_completion = -1;
+
+/*************
+ * Callbacks *
+ *************/
+
+static void replace_bdw_ns3(char ** bdw)
+{
+  char *temp = xbt_strdup(*bdw);
+  xbt_free(*bdw);
+  *bdw = bprintf("%fBps",atof(temp));
+  xbt_free(temp);
+
+}
+
+static void replace_lat_ns3(char ** lat)
+{
+  char *temp = xbt_strdup(*lat);
+  xbt_free(*lat);
+  *lat = bprintf("%fs",atof(temp));
+  xbt_free(temp);
+}
+
+static void parse_ns3_add_host(sg_platf_host_cbarg_t host)
+{
+  XBT_DEBUG("NS3_ADD_HOST '%s'",host->id);
+  xbt_lib_set(host_lib,
+              host->id,
+              NS3_HOST_LEVEL,
+              ns3_add_host(host->id)
+    );
+}
+
+static void parse_ns3_add_link(sg_platf_link_cbarg_t link)
+{
+  XBT_DEBUG("NS3_ADD_LINK '%s'",link->id);
+
+  if(!IPV4addr) IPV4addr = xbt_dynar_new(sizeof(char*),free);
+
+  NetworkLinkPtr net_link = 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_lib_set(link_lib, link->id, SURF_LINK_LEVEL, net_link);
+}
+
+static void parse_ns3_add_router(sg_platf_router_cbarg_t router)
+{
+  XBT_DEBUG("NS3_ADD_ROUTER '%s'",router->id);
+  xbt_lib_set(as_router_lib,
+              router->id,
+              NS3_ASR_LEVEL,
+              ns3_add_router(router->id)
+    );
+}
+
+static void parse_ns3_add_AS(sg_platf_AS_cbarg_t AS)
+{
+  XBT_DEBUG("NS3_ADD_AS '%s'",AS->id);
+  xbt_lib_set(as_router_lib,
+              AS->id,
+              NS3_ASR_LEVEL,
+              ns3_add_AS(AS->id)
+    );
+}
+
+static void parse_ns3_add_cluster(sg_platf_cluster_cbarg_t cluster)
+{
+  const char *cluster_prefix = cluster->prefix;
+  const char *cluster_suffix = cluster->suffix;
+  const char *cluster_radical = cluster->radical;
+  const char *cluster_bb_bw = bprintf("%f",cluster->bb_bw);
+  const char *cluster_bb_lat = bprintf("%f",cluster->bb_lat);
+  const char *cluster_bw = bprintf("%f",cluster->bw);
+  const char *cluster_lat = bprintf("%f",cluster->lat);
+  const char *groups = NULL;
+
+  int start, end, i;
+  unsigned int iter;
+
+  xbt_dynar_t radical_elements;
+  xbt_dynar_t radical_ends;
+  xbt_dynar_t tab_elements_num = xbt_dynar_new(sizeof(int), NULL);
+
+  char *router_id,*host_id;
+
+  radical_elements = xbt_str_split(cluster_radical, ",");
+  xbt_dynar_foreach(radical_elements, iter, groups) {
+    radical_ends = xbt_str_split(groups, "-");
+
+    switch (xbt_dynar_length(radical_ends)) {
+    case 1:
+      start = surf_parse_get_int(xbt_dynar_get_as(radical_ends, 0, char *));
+      xbt_dynar_push_as(tab_elements_num, int, start);
+      router_id = bprintf("ns3_%s%d%s", cluster_prefix, start, cluster_suffix);
+      xbt_lib_set(host_lib,
+                  router_id,
+                  NS3_HOST_LEVEL,
+                  ns3_add_host_cluster(router_id)
+        );
+      XBT_DEBUG("NS3_ADD_ROUTER '%s'",router_id);
+      free(router_id);
+      break;
+
+    case 2:
+      start = surf_parse_get_int(xbt_dynar_get_as(radical_ends, 0, char *));
+      end = surf_parse_get_int(xbt_dynar_get_as(radical_ends, 1, char *));
+      for (i = start; i <= end; i++){
+        xbt_dynar_push_as(tab_elements_num, int, i);
+        router_id = bprintf("ns3_%s%d%s", cluster_prefix, i, cluster_suffix);
+        xbt_lib_set(host_lib,
+                    router_id,
+                    NS3_HOST_LEVEL,
+                    ns3_add_host_cluster(router_id)
+          );
+        XBT_DEBUG("NS3_ADD_ROUTER '%s'",router_id);
+        free(router_id);
+      }
+      break;
+
+    default:
+      XBT_DEBUG("Malformed radical");
+    }
+  }
+
+  //Create links
+  unsigned int cpt;
+  int elmts;
+  char * lat = xbt_strdup(cluster_lat);
+  char * bw =  xbt_strdup(cluster_bw);
+  replace_lat_ns3(&lat);
+  replace_bdw_ns3(&bw);
+
+  xbt_dynar_foreach(tab_elements_num,cpt,elmts)
+  {
+    host_id   = bprintf("%s%d%s", cluster_prefix, elmts, cluster_suffix);
+    router_id = bprintf("ns3_%s%d%s", cluster_prefix, elmts, cluster_suffix);
+    XBT_DEBUG("Create link from '%s' to '%s'",host_id,router_id);
+
+    ns3_nodes_t host_src = static_cast<ns3_nodes_t>(xbt_lib_get_or_null(host_lib,host_id,  NS3_HOST_LEVEL));
+    ns3_nodes_t host_dst = static_cast<ns3_nodes_t>(xbt_lib_get_or_null(host_lib,router_id,NS3_HOST_LEVEL));
+
+    if(host_src && host_dst){}
+    else xbt_die("\tns3_add_link from %d to %d",host_src->node_num,host_dst->node_num);
+
+    ns3_add_link(host_src->node_num,host_src->type,
+                 host_dst->node_num,host_dst->type,
+                 bw,lat);
+
+    free(router_id);
+    free(host_id);
+  }
+  xbt_dynar_free(&tab_elements_num);
+
+
+  //Create link backbone
+  lat = xbt_strdup(cluster_bb_lat);
+  bw =  xbt_strdup(cluster_bb_bw);
+  replace_lat_ns3(&lat);
+  replace_bdw_ns3(&bw);
+  ns3_add_cluster(bw,lat,cluster->id);
+  xbt_free(lat);
+  xbt_free(bw);
+}
+
+/* Create the ns3 topology based on routing strategy */
+static void create_ns3_topology(void)
+{
+  XBT_DEBUG("Starting topology generation");
+
+  xbt_dynar_shrink(IPV4addr,0);
+
+  //get the onelinks from the parsed platform
+  xbt_dynar_t onelink_routes = routing_platf->getOneLinkRoutes();
+  if (!onelink_routes)
+    xbt_die("There is no routes!");
+  XBT_DEBUG("Have get_onelink_routes, found %ld routes",onelink_routes->used);
+  //save them in trace file
+  OnelinkPtr onelink;
+  unsigned int iter;
+  xbt_dynar_foreach(onelink_routes, iter, onelink) {
+    char *src = onelink->p_src->getName();
+    char *dst = onelink->p_dst->getName();
+    NetworkNS3LinkPtr link = static_cast<NetworkNS3LinkPtr>(onelink->p_link);
+
+    if (strcmp(src,dst) && link->m_created){
+      XBT_DEBUG("Route from '%s' to '%s' with link '%s'", src, dst, link->getName());
+      char * link_bdw = xbt_strdup(link->p_bdw);
+      char * link_lat = xbt_strdup(link->p_lat);
+      replace_lat_ns3(&link_lat);
+      replace_bdw_ns3(&link_bdw);
+      link->m_created = 0;
+
+      //   XBT_DEBUG("src (%s), dst (%s), src_id = %d, dst_id = %d",src,dst, src_id, dst_id);
+      XBT_DEBUG("\tLink (%s) bdw:%s lat:%s", link->getName(), link_bdw, link_lat);
+
+      //create link ns3
+      ns3_nodes_t host_src = static_cast<ns3_nodes_t>(xbt_lib_get_or_null(host_lib,src,NS3_HOST_LEVEL));
+      if(!host_src) host_src = static_cast<ns3_nodes_t>(xbt_lib_get_or_null(as_router_lib,src,NS3_ASR_LEVEL));
+      ns3_nodes_t host_dst = static_cast<ns3_nodes_t>(xbt_lib_get_or_null(host_lib,dst,NS3_HOST_LEVEL));
+      if(!host_dst) host_dst = static_cast<ns3_nodes_t>(xbt_lib_get_or_null(as_router_lib,dst,NS3_ASR_LEVEL));
+
+      if(host_src && host_dst){}
+      else xbt_die("\tns3_add_link from %d to %d",host_src->node_num,host_dst->node_num);
+
+      ns3_add_link(host_src->node_num,host_src->type,host_dst->node_num,host_dst->type,link_bdw,link_lat);
+
+      xbt_free(link_bdw);
+      xbt_free(link_lat);
+    }
+  }
+}
+
+static void parse_ns3_end_platform(void)
+{
+  ns3_end_platform();
+}
+
+static void define_callbacks_ns3(void)
+{
+  sg_platf_host_add_cb (&parse_ns3_add_host);
+  sg_platf_router_add_cb (&parse_ns3_add_router);
+  sg_platf_link_add_cb (&parse_ns3_add_link);
+  sg_platf_cluster_add_cb (&parse_ns3_add_cluster);
+  sg_platf_AS_begin_add_cb (&parse_ns3_add_AS);
+  sg_platf_postparse_add_cb(&create_ns3_topology); //get_one_link_routes
+  sg_platf_postparse_add_cb(&parse_ns3_end_platform); //InitializeRoutes
+}
+
+/*********
+ * Model *
+ *********/
+static void free_ns3_link(void * elmts)
+{
+  delete static_cast<NetworkNS3LinkPtr>(elmts);
+}
+
+static void free_ns3_host(void * elmts)
+{
+  ns3_nodes_t host = static_cast<ns3_nodes_t>(elmts);
+  free(host);
+}
+
+void surf_network_model_init_NS3()
+{
+  if (surf_network_model)
+    return;
+
+  surf_network_model = new NetworkNS3Model();
+
+  xbt_dynar_push(model_list, &surf_network_model);
+}
+
+NetworkNS3Model::NetworkNS3Model() : NetworkModel("network NS3") {
+  if (ns3_initialize(xbt_cfg_get_string(_sg_cfg_set, "ns3/TcpModel"))) {
+    xbt_die("Impossible to initialize NS3 interface");
+  }
+  routing_model_create(NULL);
+  define_callbacks_ns3();
+
+  NS3_HOST_LEVEL = xbt_lib_add_level(host_lib,(void_f_pvoid_t)free_ns3_host);
+  NS3_ASR_LEVEL  = xbt_lib_add_level(as_router_lib,(void_f_pvoid_t)free_ns3_host);
+  NS3_LINK_LEVEL = xbt_lib_add_level(link_lib,(void_f_pvoid_t)free_ns3_link);
+}
+
+NetworkNS3Model::~NetworkNS3Model() {
+  ns3_finalize();
+  xbt_dynar_free_container(&IPV4addr);
+  xbt_dict_free(&dict_socket);
+}
+
+NetworkLinkPtr NetworkNS3Model::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){
+  if (bw_trace)
+    XBT_INFO("The NS3 network model doesn't support bandwidth state traces");
+  if (lat_trace)
+    XBT_INFO("The NS3 network model doesn't support latency state traces");
+  if (state_trace)
+    XBT_INFO("The NS3 network model doesn't support link state traces");
+  return new NetworkNS3Link(this, name, properties, bw_initial, lat_initial);
+}
+
+xbt_dynar_t NetworkNS3Model::getRoute(RoutingEdgePtr src, RoutingEdgePtr dst)
+{
+  xbt_dynar_t route = NULL;
+  routing_get_route_and_latency(src, dst, &route, NULL);
+  //routing_platf->getRouteAndLatency(src, dst, &route, NULL);
+  return route;
+}
+
+ActionPtr NetworkNS3Model::communicate(RoutingEdgePtr src, RoutingEdgePtr dst,
+                                              double size, double rate)
+{
+  XBT_DEBUG("Communicate from %s to %s", src->getName(), dst->getName());
+  NetworkNS3ActionPtr action = new NetworkNS3Action(this, size, 0);
+
+  ns3_create_flow(src->getName(), dst->getName(), surf_get_clock(), size, action);
+
+#ifdef HAVE_TRACING
+  action->m_lastSent = 0;
+  action->p_srcElm = src;
+  action->p_dstElm = dst;
+#endif
+
+  return (surf_action_t) action;
+}
+
+double NetworkNS3Model::shareResources(double now)
+{
+  XBT_DEBUG("ns3_share_resources");
+
+  //get the first relevant value from the running_actions list
+  if (!getRunningActionSet()->size() || now == 0.0)
+    return -1.0;
+  else
+    do {
+      ns3_simulator(now);
+      time_to_next_flow_completion = ns3_time() - surf_get_clock();//FIXME: use now instead ?
+    } while(double_equals(time_to_next_flow_completion, 0));
+
+  XBT_DEBUG("min       : %f", now);
+  XBT_DEBUG("ns3  time : %f", ns3_time());
+  XBT_DEBUG("surf time : %f", surf_get_clock());
+  XBT_DEBUG("Next completion %f :", time_to_next_flow_completion);
+
+  return time_to_next_flow_completion;
+}
+
+void NetworkNS3Model::updateActionsState(double now, double delta)
+{
+  xbt_dict_cursor_t cursor = NULL;
+  char *key;
+  void *data;
+
+  static xbt_dynar_t socket_to_destroy = NULL;
+  if(!socket_to_destroy) socket_to_destroy = xbt_dynar_new(sizeof(char*),NULL);
+
+  /* If there are no running flows, just return */
+  if (!getRunningActionSet()->size()) {
+    while(double_positive(now-ns3_time())) {
+      ns3_simulator(now-ns3_time());
+    }
+    return;
+  }
+
+  NetworkNS3ActionPtr action;
+  xbt_dict_foreach(dict_socket,cursor,key,data){
+    action = static_cast<NetworkNS3ActionPtr>(ns3_get_socket_action(data));
+    XBT_DEBUG("Processing socket %p (action %p)",data,action);
+    action->setRemains(action->getCost() - ns3_get_socket_sent(data));
+
+    #ifdef HAVE_TRACING
+      if (TRACE_is_enabled() &&
+          action->getState() == SURF_ACTION_RUNNING){
+        double data_sent = ns3_get_socket_sent(data);
+        double data_delta_sent = data_sent - action->m_lastSent;
+
+        xbt_dynar_t route = NULL;
+
+        routing_get_route_and_latency (action->p_srcElm, action->p_dstElm, &route, NULL);
+        unsigned int i;
+        for (i = 0; i < xbt_dynar_length (route); i++){
+               NetworkNS3LinkPtr link = ((NetworkNS3LinkPtr)xbt_dynar_get_ptr (route, i));
+          TRACE_surf_link_set_utilization (link->getName(),
+                                           action->getCategory(),
+                                           (data_delta_sent)/delta,
+                                           now-delta,
+                                           delta);
+        }
+        action->m_lastSent = data_sent;
+      }
+    #endif
+
+    if(ns3_get_socket_is_finished(data) == 1){
+      xbt_dynar_push(socket_to_destroy,&key);
+      XBT_DEBUG("Destroy socket %p of action %p", key, action);
+      action->finish();
+      action->setState(SURF_ACTION_DONE);
+    }
+  }
+
+  while (!xbt_dynar_is_empty(socket_to_destroy)){
+    xbt_dynar_pop(socket_to_destroy,&key);
+
+    void *data = xbt_dict_get (dict_socket, key);
+    action = static_cast<NetworkNS3ActionPtr>(ns3_get_socket_action(data));
+    XBT_DEBUG ("Removing socket %p of action %p", key, action);
+    xbt_dict_remove(dict_socket, key);
+  }
+  return;
+}
+
+/************
+ * Resource *
+ ************/
+
+NetworkNS3Link::NetworkNS3Link(NetworkNS3ModelPtr model, const char *name, xbt_dict_t props,
+                                      double bw_initial, double lat_initial)
+ : NetworkLink(model, name, props)
+ , p_bdw(bprintf("%f", bw_initial))
+ , p_lat(bprintf("%f", lat_initial))
+ , m_created(1)
+{
+}
+
+NetworkNS3Link::~NetworkNS3Link()
+{
+}
+
+void NetworkNS3Link::updateState(tmgr_trace_event_t event_type, double value, double date)
+{
+
+}
+double NetworkNS3Link::getLatency()
+{
+
+}
+double NetworkNS3Link::getBandwidth()
+{
+
+}
+
+/**********
+ * Action *
+ **********/
+
+NetworkNS3Action::NetworkNS3Action(ModelPtr model, double cost, bool failed)
+: NetworkAction(model, cost, failed)
+{}
+
+#ifdef HAVE_LATENCY_BOUND_TRACKING
+  int NetworkNS3Action::getLatencyLimited() {
+    return m_latencyLimited;
+  }
+#endif
+
+ void NetworkNS3Action::suspend()
+{
+  THROW_UNIMPLEMENTED;
+}
+
+void NetworkNS3Action::resume()
+{
+  THROW_UNIMPLEMENTED;
+}
+
+  /* Test whether a flow is suspended */
+bool NetworkNS3Action::isSuspended()
+{
+  return 0;
+}
+
+int NetworkNS3Action::unref()
+{
+  m_refcount--;
+  if (!m_refcount) {
+       if (actionHook::is_linked())
+         p_stateSet->erase(p_stateSet->iterator_to(*this));
+    XBT_DEBUG ("Removing action %p", this);
+       delete this;
+    return 1;
+  }
+  return 0;
+}
diff --git a/src/surf/network_ns3.hpp b/src/surf/network_ns3.hpp
new file mode 100644 (file)
index 0000000..f5389b8
--- /dev/null
@@ -0,0 +1,99 @@
+/* Copyright (c) 2004-2014. The SimGrid Team.
+ *
+ * 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 "network_interface.hpp"
+#include "surf/ns3/ns3_interface.h"
+
+#ifndef NETWORK_NS3_HPP_
+#define NETWORK_NS3_HPP_
+
+/***********
+ * Classes *
+ ***********/
+class NetworkNS3Model;
+typedef NetworkNS3Model *NetworkNS3ModelPtr;
+
+class NetworkNS3Link;
+typedef NetworkNS3Link *NetworkNS3LinkPtr;
+
+class NetworkNS3Action;
+typedef NetworkNS3Action *NetworkNS3ActionPtr;
+
+/*********
+ * Tools *
+ *********/
+
+void net_define_callbacks(void);
+
+/*********
+ * Model *
+ *********/
+
+class NetworkNS3Model : public NetworkModel {
+public:
+  NetworkNS3Model();
+
+  ~NetworkNS3Model();
+  NetworkLinkPtr 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(RoutingEdgePtr src, RoutingEdgePtr dst);
+  ActionPtr communicate(RoutingEdgePtr src, RoutingEdgePtr dst,
+                                          double size, double rate);
+  double shareResources(double now);
+  void updateActionsState(double now, double delta);
+};
+
+/************
+ * Resource *
+ ************/
+class NetworkNS3Link : public NetworkLink {
+public:
+  NetworkNS3Link(NetworkNS3ModelPtr model, const char *name, xbt_dict_t props,
+                        double bw_initial, double lat_initial);
+  ~NetworkNS3Link();
+
+  void updateState(tmgr_trace_event_t event_type, double value, double date);
+  double getLatency();
+  double getBandwidth();
+
+//private:
+ char *p_id;
+ char *p_lat;
+ char *p_bdw;
+ int m_created;
+};
+
+/**********
+ * Action *
+ **********/
+class NetworkNS3Action : public NetworkAction {
+public:
+  NetworkNS3Action(ModelPtr model, double cost, bool failed);
+
+#ifdef HAVE_LATENCY_BOUND_TRACKING
+  int getLatencyLimited();
+#endif
+
+bool isSuspended();
+int unref();
+void suspend();
+void resume();
+
+//private:
+#ifdef HAVE_TRACING
+  double m_lastSent;
+  RoutingEdgePtr p_srcElm;
+  RoutingEdgePtr p_dstElm;
+#endif //HAVE_TRACING
+};
+
+
+#endif /* NETWORK_NS3_HPP_ */
index 8c759df..b5a80b8 100644 (file)
@@ -23,7 +23,7 @@
  * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
  */
 
  * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
  */
 
-#include "ns3/abort.h"
+#include <ns3/abort.h>
 #include "ns3/log.h"
 #include "ns3/simulator.h"
 #include "ns3/point-to-point-net-device.h"
 #include "ns3/log.h"
 #include "ns3/simulator.h"
 #include "ns3/point-to-point-net-device.h"
index f42a7a8..4c3d591 100644 (file)
@@ -234,7 +234,6 @@ void * ns3_add_link(int src, e_ns3_network_element_type_t type_src,
                LogComponentEnable("UdpEchoServerApplication", LOG_LEVEL_INFO);
        }
 
                LogComponentEnable("UdpEchoServerApplication", LOG_LEVEL_INFO);
        }
 
-
        MyPointToPointHelper pointToPoint;
 
        NetDeviceContainer netA;
        MyPointToPointHelper pointToPoint;
 
        NetDeviceContainer netA;
index 15ab8f7..f153403 100644 (file)
@@ -135,7 +135,7 @@ double surf_solve(double max_date)
 
     next_event_date = tmgr_history_next_date(history);
 
 
     next_event_date = tmgr_history_next_date(history);
 
-    if(!strcmp(surf_network_model->getName(), "network NS3")){//FIXME: add surf_network_model->m_name &&
+    if(!strcmp(surf_network_model->getName(), "network NS3")){
       if(next_event_date!=-1.0 && surf_min!=-1.0) {
         surf_min = MIN(next_event_date - NOW, surf_min);
       } else{
       if(next_event_date!=-1.0 && surf_min!=-1.0) {
         surf_min = MIN(next_event_date - NOW, surf_min);
       } else{
@@ -541,6 +541,10 @@ void surf_cpu_action_set_bound(surf_action_t action, double bound) {
   static_cast<CpuActionPtr>(action)->setBound(bound);
 }
 
   static_cast<CpuActionPtr>(action)->setBound(bound);
 }
 
+double surf_network_action_get_latency_limited(surf_action_t action) {
+  return static_cast<NetworkActionPtr>(action)->getLatencyLimited();
+}
+
 surf_file_t surf_storage_action_get_file(surf_action_t action){
   return static_cast<StorageActionPtr>(action)->p_file;
 }
 surf_file_t surf_storage_action_get_file(surf_action_t action){
   return static_cast<StorageActionPtr>(action)->p_file;
 }
index f1eaef9..c68f912 100644 (file)
@@ -616,15 +616,6 @@ public:
    */
   double getRemainsNoUpdate();
 
    */
   double getRemainsNoUpdate();
 
-#ifdef HAVE_LATENCY_BOUND_TRACKING
-  /**
-   * @brief Check if the action is limited by latency.
-   * 
-   * @return 1 if action is limited by latency, 0 otherwise
-   */
-  int getLatencyLimited();
-#endif
-
   /**
    * @brief Get the priority of the current Action
    * 
   /**
    * @brief Get the priority of the current Action
    * 
index a788edc..4bea656 100644 (file)
@@ -135,7 +135,7 @@ double WorkstationVMHL13Model::shareResources(double now)
   adjustWeightOfDummyCpuActions();
 
   double min_by_cpu = p_cpuModel->shareResources(now);
   adjustWeightOfDummyCpuActions();
 
   double min_by_cpu = p_cpuModel->shareResources(now);
-  double min_by_net = surf_network_model->shareResources(now);
+  double min_by_net = (strcmp(surf_network_model->getName(), "network NS3")) ? surf_network_model->shareResources(now) : -1;
   double min_by_sto = -1;
   if (p_cpuModel == surf_cpu_model_pm)
        min_by_sto = surf_storage_model->shareResources(now);
   double min_by_sto = -1;
   if (p_cpuModel == surf_cpu_model_pm)
        min_by_sto = surf_storage_model->shareResources(now);
index a9bd3d1..1848fd5 100644 (file)
@@ -82,7 +82,7 @@ double WorkstationCLM03Model::shareResources(double now){
   adjustWeightOfDummyCpuActions();
 
   double min_by_cpu = p_cpuModel->shareResources(now);
   adjustWeightOfDummyCpuActions();
 
   double min_by_cpu = p_cpuModel->shareResources(now);
-  double min_by_net = surf_network_model->shareResources(now);
+  double min_by_net = (strcmp(surf_network_model->getName(), "network NS3")) ? surf_network_model->shareResources(now) : -1;
   double min_by_sto = -1;
   if (p_cpuModel == surf_cpu_model_pm)
        min_by_sto = surf_storage_model->shareResources(now);
   double min_by_sto = -1;
   if (p_cpuModel == surf_cpu_model_pm)
        min_by_sto = surf_storage_model->shareResources(now);