Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add networkCommunicateCallback, NetworkLink::updateLatency and NetworkLink::updateBan...
authorPaul Bédaride <paul.bedaride@gmail.com>
Wed, 26 Mar 2014 16:02:09 +0000 (17:02 +0100)
committerPaul Bédaride <paul.bedaride@gmail.com>
Wed, 26 Mar 2014 16:03:48 +0000 (17:03 +0100)
12 files changed:
src/surf/network_cm02.cpp
src/surf/network_cm02.hpp
src/surf/network_constant.cpp
src/surf/network_interface.cpp
src/surf/network_interface.hpp
src/surf/network_ns3.cpp
src/surf/network_ns3.hpp
src/surf/ns3/ns3_interface.cc
src/surf/ns3/ns3_interface.h
src/surf/surf_interface.cpp
src/surf/workstation_ptask_L07.cpp
src/surf/workstation_ptask_L07.hpp

index b80ddfd..66e5883 100644 (file)
@@ -482,6 +482,7 @@ ActionPtr NetworkCm02Model::communicate(RoutingEdgePtr src, RoutingEdgePtr dst,
   xbt_dynar_free(&route);
   XBT_OUT();
 
+  surf_callback_emit(networkCommunicateCallbacks, action, src, dst, size, rate);
   return action;
 }
 
@@ -530,59 +531,11 @@ void NetworkCm02Link::updateState(tmgr_trace_event_t event_type,
   /*     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;
-    NetworkCm02ActionPtr action = NULL;
-
-    p_power.peak = value;
-    lmm_update_constraint_bound(getModel()->getMaxminSystem(),
-                                   getConstraint(),
-                                sg_bandwidth_factor *
-                                (p_power.peak * p_power.scale));
-#ifdef HAVE_TRACING
-    TRACE_surf_link_set_bandwidth(date, getName(), sg_bandwidth_factor * p_power.peak * p_power.scale);
-#endif
-    if (sg_weight_S_parameter > 0) {
-      while ((var = lmm_get_var_from_cnst(getModel()->getMaxminSystem(), getConstraint(), &elem))) {
-        action = (NetworkCm02ActionPtr) lmm_variable_id(var);
-        action->m_weight += delta;
-        if (!action->isSuspended())
-          lmm_update_variable_weight(getModel()->getMaxminSystem(), action->getVariable(), action->m_weight);
-      }
-    }
+    updateBandwidth(value, date);
     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;
-    NetworkCm02ActionPtr action = NULL;
-
-    m_latCurrent = value;
-    while ((var = lmm_get_var_from_cnst(getModel()->getMaxminSystem(), getConstraint(), &elem))) {
-      action = (NetworkCm02ActionPtr) lmm_variable_id(var);
-      action->m_latCurrent += delta;
-      action->m_weight += delta;
-      if (action->m_rate < 0)
-        lmm_update_variable_bound(getModel()->getMaxminSystem(), action->getVariable(), sg_tcp_gamma / (2.0 * action->m_latCurrent));
-      else {
-        lmm_update_variable_bound(getModel()->getMaxminSystem(), action->getVariable(),
-                                  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->isSuspended())
-        lmm_update_variable_weight(getModel()->getMaxminSystem(), action->getVariable(), action->m_weight);
-
-    }
+    updateLatency(value, date);
     if (tmgr_trace_event_free(event_type))
       p_latEvent = NULL;
   } else if (event_type == p_stateEvent) {
@@ -617,6 +570,60 @@ void NetworkCm02Link::updateState(tmgr_trace_event_t event_type,
   return;
 }
 
+void NetworkCm02Link::updateBandwidth(double value, double date){
+  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;
+  NetworkCm02ActionPtr action = NULL;
+
+  p_power.peak = value;
+  lmm_update_constraint_bound(getModel()->getMaxminSystem(),
+                              getConstraint(),
+                              sg_bandwidth_factor *
+                              (p_power.peak * p_power.scale));
+#ifdef HAVE_TRACING
+  TRACE_surf_link_set_bandwidth(date, getName(), sg_bandwidth_factor * p_power.peak * p_power.scale);
+#endif
+  if (sg_weight_S_parameter > 0) {
+    while ((var = lmm_get_var_from_cnst(getModel()->getMaxminSystem(), getConstraint(), &elem))) {
+      action = (NetworkCm02ActionPtr) lmm_variable_id(var);
+      action->m_weight += delta;
+      if (!action->isSuspended())
+        lmm_update_variable_weight(getModel()->getMaxminSystem(), action->getVariable(), action->m_weight);
+    }
+  }
+}
+
+void NetworkCm02Link::updateLatency(double value, double date){
+  double delta = value - m_latCurrent;
+  lmm_variable_t var = NULL;
+  lmm_element_t elem = NULL;
+  NetworkCm02ActionPtr action = NULL;
+
+  m_latCurrent = value;
+  while ((var = lmm_get_var_from_cnst(getModel()->getMaxminSystem(), getConstraint(), &elem))) {
+    action = (NetworkCm02ActionPtr) lmm_variable_id(var);
+    action->m_latCurrent += delta;
+    action->m_weight += delta;
+    if (action->m_rate < 0)
+      lmm_update_variable_bound(getModel()->getMaxminSystem(), action->getVariable(), sg_tcp_gamma / (2.0 * action->m_latCurrent));
+    else {
+      lmm_update_variable_bound(getModel()->getMaxminSystem(), action->getVariable(),
+                                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->isSuspended())
+      lmm_update_variable_weight(getModel()->getMaxminSystem(), action->getVariable(), action->m_weight);
+  }
+}
+
 /**********
  * Action *
  **********/
index b4d4048..c31c1c9 100644 (file)
@@ -80,6 +80,8 @@ public:
                                   tmgr_trace_t lat_trace,
                                e_surf_link_sharing_policy_t policy);
   void updateState(tmgr_trace_event_t event_type, double value, double date);
+  void updateBandwidth(double value, double date=surf_get_clock());
+  void updateLatency(double value, double date=surf_get_clock());
 };
 
 
index d9f36dd..e813122 100644 (file)
@@ -88,6 +88,7 @@ ActionPtr NetworkConstantModel::communicate(RoutingEdgePtr src, RoutingEdgePtr d
   NetworkConstantActionPtr action = new NetworkConstantAction(this, size, sg_latency_factor);
   XBT_OUT();
 
+  surf_callback_emit(networkCommunicateCallbacks, action, src, dst, size, rate);
   return action;
 }
 
index f6d1863..39195ef 100644 (file)
@@ -21,6 +21,7 @@ surf_callback(void, NetworkLinkPtr) networkLinkCreatedCallbacks;
 surf_callback(void, NetworkLinkPtr) networkLinkDestructedCallbacks;
 surf_callback(void, NetworkLinkPtr, e_surf_resource_state_t, e_surf_resource_state_t) networkLinkStateChangedCallbacks;
 surf_callback(void, NetworkActionPtr, e_surf_action_state_t, e_surf_action_state_t) networkActionStateChangedCallbacks;
+surf_callback(void, NetworkActionPtr, RoutingEdgePtr src, RoutingEdgePtr dst, double size, double rate) networkCommunicateCallbacks;
 
 /*********
  * Model *
@@ -102,7 +103,6 @@ void NetworkAction::setState(e_surf_action_state_t state){
   e_surf_action_state_t old = getState();
   Action::setState(state);
   surf_callback_emit(networkActionStateChangedCallbacks, this, old, state);
-
 }
 
 #endif /* NETWORK_INTERFACE_CPP_ */
index 37241e4..05792b2 100644 (file)
@@ -50,6 +50,12 @@ extern surf_callback(void, NetworkLinkPtr, e_surf_resource_state_t, e_surf_resou
  */
 extern surf_callback(void, NetworkActionPtr, e_surf_action_state_t, e_surf_action_state_t) networkActionStateChangedCallbacks;
 
+/** @ingroup SURF_callbacks
+ * @brief Callbacks handler which emit the callbacks after communication created
+ * @details Callback functions have the following signature: `void(NetworkActionPtr action, RoutingEdgePtr src, RoutingEdgePtr dst, double size, double rate)`
+ */
+extern surf_callback(void, NetworkActionPtr, RoutingEdgePtr src, RoutingEdgePtr dst, double size, double rate) networkCommunicateCallbacks;
+
 /*********
  * Tools *
  *********/
@@ -216,6 +222,11 @@ public:
    */
   virtual double getBandwidth();
 
+  /**
+   * @brief Update the bandwidth in bytes per second of current NetworkLink
+   */
+  virtual void updateBandwidth(double value, double date=surf_get_clock())=0;
+
   /**
    * @brief Get the latency in seconds of current NetworkLink
    *
@@ -223,6 +234,11 @@ public:
    */
   virtual double getLatency();
 
+  /**
+   * @brief Update the latency in seconds of current NetworkLink
+   */
+  virtual void updateLatency(double value, double date=surf_get_clock())=0;
+
   /**
    * @brief Check if the NetworkLink is shared
    * @details [long description]
index 4fecb0f..b133fb8 100644 (file)
@@ -331,6 +331,7 @@ ActionPtr NetworkNS3Model::communicate(RoutingEdgePtr src, RoutingEdgePtr dst,
   action->p_srcElm = src;
   action->p_dstElm = dst;
 #endif
+  surf_callback_emit(networkCommunicateCallbacks, action, src, dst, size, rate);
 
   return (surf_action_t) action;
 }
@@ -427,8 +428,8 @@ void NetworkNS3Model::updateActionsState(double now, double delta)
 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))
+ , p_bdw(bprintf("%f", bw_initial))
  , m_created(1)
 {
 }
@@ -440,14 +441,6 @@ NetworkNS3Link::~NetworkNS3Link()
 void NetworkNS3Link::updateState(tmgr_trace_event_t event_type, double value, double date)
 {
 
-}
-double NetworkNS3Link::getLatency()
-{
-
-}
-double NetworkNS3Link::getBandwidth()
-{
-
 }
 
 /**********
index f5389b8..8aab263 100644 (file)
@@ -61,8 +61,10 @@ public:
   ~NetworkNS3Link();
 
   void updateState(tmgr_trace_event_t event_type, double value, double date);
-  double getLatency();
-  double getBandwidth();
+  double getLatency(){THROW_UNIMPLEMENTED;}
+  double getBandwidth(){THROW_UNIMPLEMENTED;}
+  void updateBandwidth(double value, double date=surf_get_clock()){THROW_UNIMPLEMENTED;}
+  void updateLatency(double value, double date=surf_get_clock()){THROW_UNIMPLEMENTED;}
 
 //private:
  char *p_id;
index 4c3d591..900f77b 100644 (file)
@@ -122,6 +122,7 @@ int ns3_initialize(const char* TcpProtocol){
   }
 
   XBT_ERROR("The ns3/TcpModel must be : NewReno or Reno or Tahoe");
+  return 0;
 }
 
 void * ns3_add_host(const char * id)
@@ -167,7 +168,7 @@ void * ns3_add_router(const char * id)
        return router;
 }
 
-void ns3_add_cluster(char * bw,char * lat,const char *id)
+void ns3_add_cluster(char * bw,char * lat,const char *id)
 {
 
        XBT_DEBUG("cluster_id: %s",id);
@@ -175,7 +176,7 @@ void * ns3_add_cluster(char * bw,char * lat,const char *id)
        XBT_DEBUG("Number of %s nodes: %d",id,Cluster_nodes.GetN() - number_of_clusters_nodes);
 
        NodeContainer Nodes;
-       int i;
+       unsigned int i;
 
        for(i = number_of_clusters_nodes; i < Cluster_nodes.GetN() ; i++){
                Nodes.Add(Cluster_nodes.Get(i));
@@ -225,7 +226,7 @@ static char* transformIpv4Address (Ipv4Address from){
                return bprintf("%s",s.c_str());
 }
 
-void ns3_add_link(int src, e_ns3_network_element_type_t type_src,
+void ns3_add_link(int src, e_ns3_network_element_type_t type_src,
                                        int dst, e_ns3_network_element_type_t type_dst,
                                        char * bw,char * lat)
 {
@@ -273,7 +274,7 @@ void * ns3_add_link(int src, e_ns3_network_element_type_t type_src,
        }
 }
 
-void ns3_end_platform(void)
+void ns3_end_platform(void)
 {
        XBT_DEBUG("InitializeRoutes");
        GlobalRouteManager::BuildGlobalRoutingDatabase();
index db6b193..8aaf466 100644 (file)
@@ -40,11 +40,11 @@ XBT_PUBLIC(void *) ns3_add_host(const char * id);
 XBT_PUBLIC(void *) ns3_add_host_cluster(const char * id);
 XBT_PUBLIC(void *) ns3_add_router(const char * id);
 XBT_PUBLIC(void *) ns3_add_AS(const char * id);
-XBT_PUBLIC(void *) ns3_add_link(int src, e_ns3_network_element_type_t type_src,
+XBT_PUBLIC(void) ns3_add_link(int src, e_ns3_network_element_type_t type_src,
                 int dst, e_ns3_network_element_type_t type_dst,
                 char * bw,char * lat);
-XBT_PUBLIC(void *) ns3_end_platform(void);
-XBT_PUBLIC(void *) ns3_add_cluster(char * bw,char * lat,const char *id);
+XBT_PUBLIC(void) ns3_end_platform(void);
+XBT_PUBLIC(void) ns3_add_cluster(char * bw,char * lat,const char *id);
 
 SG_END_DECL()
 
index 6be998b..56454da 100644 (file)
@@ -260,7 +260,7 @@ static const char *disk_drives_letter_table[MAX_DRIVE] = {
   "Y:\\",
   "Z:\\"
 };
-#endif  
+#endif
 
 /*
  * Returns the initial path. On Windows the initial path is
@@ -872,8 +872,8 @@ void Action::setBound(double bound)
   if (p_variable)
     lmm_update_variable_bound(getModel()->getMaxminSystem(), getVariable(), bound);
 
-  if (getModel()->getUpdateMechanism() == UM_LAZY)
-       heapRemove(getModel()->getActionHeap());
+  if (getModel()->getUpdateMechanism() == UM_LAZY && getLastUpdate()!=surf_get_clock())
+         heapRemove(getModel()->getActionHeap());
   XBT_OUT();
 }
 
index f44c1a1..71d2a57 100644 (file)
@@ -502,20 +502,11 @@ void CpuL07::updateState(tmgr_trace_event_t event_type, double value, double /*d
 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", getName(), this, value, date);
   if (event_type == p_bwEvent) {
-    m_bwCurrent = value;
-    lmm_update_constraint_bound(ptask_maxmin_system, getConstraint(), m_bwCurrent);
+    updateBandwidth(value, date);
     if (tmgr_trace_event_free(event_type))
       p_bwEvent = NULL;
   } else if (event_type == p_latEvent) {
-    lmm_variable_t var = NULL;
-    WorkstationL07ActionPtr action;
-    lmm_element_t elem = NULL;
-
-    m_latCurrent = value;
-    while ((var = lmm_get_var_from_cnst(ptask_maxmin_system, getConstraint(), &elem))) {
-      action = (WorkstationL07ActionPtr) lmm_variable_id(var);
-      action->updateBound();
-    }
+    updateLatency(value, date);
     if (tmgr_trace_event_free(event_type))
       p_latEvent = NULL;
   } else if (event_type == p_stateEvent) {
@@ -582,11 +573,31 @@ double LinkL07::getBandwidth()
   return m_bwCurrent;
 }
 
+void LinkL07::updateBandwidth(double value, double date)
+{
+  m_bwCurrent = value;
+  lmm_update_constraint_bound(ptask_maxmin_system, getConstraint(), m_bwCurrent);
+}
+
 double LinkL07::getLatency()
 {
   return m_latCurrent;
 }
 
+void LinkL07::updateLatency(double value, double date)
+{
+  lmm_variable_t var = NULL;
+  WorkstationL07ActionPtr action;
+  lmm_element_t elem = NULL;
+
+  m_latCurrent = value;
+  while ((var = lmm_get_var_from_cnst(ptask_maxmin_system, getConstraint(), &elem))) {
+    action = (WorkstationL07ActionPtr) lmm_variable_id(var);
+    action->updateBound();
+  }
+}
+
+
 bool LinkL07::isShared()
 {
   return lmm_constraint_is_shared(getConstraint());
index 360a851..9bcac9f 100644 (file)
@@ -164,6 +164,8 @@ public:
   double getBandwidth();
   double getLatency();
   bool isShared();
+  void updateBandwidth(double value, double date=surf_get_clock());
+  void updateLatency(double value, double date=surf_get_clock());
 
   double m_latCurrent;
   tmgr_trace_event_t p_latEvent;