Adding NS3 FDNetDevice RM
[nepi.git] / src / nepi / execution / ec.py
index 58ece22..0c92cb1 100644 (file)
@@ -41,7 +41,7 @@ import threading
 import weakref
 
 class FailureLevel(object):
-    """ Describes the system failure state """
+    """ Possible failure states for the experiment """
     OK = 1
     RM_FAILURE = 2
     EC_FAILURE = 3
@@ -49,20 +49,20 @@ class FailureLevel(object):
 class FailureManager(object):
     """ The FailureManager is responsible for handling errors
     and deciding whether an experiment should be aborted or not
-
     """
 
-    def __init__(self, ec):
-        self._ec = weakref.ref(ec)
+    def __init__(self):
+        self._ec = None
         self._failure_level = FailureLevel.OK
         self._abort = False
 
+    def set_ec(self, ec):
+        self._ec = weakref.ref(ec)
+
     @property
     def ec(self):
         """ Returns the ExperimentController associated to this FailureManager 
-        
         """
-        
         return self._ec()
 
     @property
@@ -70,6 +70,15 @@ class FailureManager(object):
         return self._abort
 
     def eval_failure(self, guid):
+        """ Implements failure policy and sets the abort state of the
+        experiment based on the failure state and criticality of
+        the RM
+
+        :param guid: Guid of the RM upon which the failure of the experiment
+            is evaluated
+        :type guid: int
+
+        """
         if self._failure_level == FailureLevel.OK:
             rm = self.ec.get_resource(guid)
             state = rm.state
@@ -85,7 +94,7 @@ class FailureManager(object):
         self._failure_level = FailureLevel.EC_FAILURE
 
 class ECState(object):
-    """ Possible states for an ExperimentController
+    """ Possible states of the ExperimentController
    
     """
     RUNNING = 1
@@ -95,11 +104,6 @@ class ECState(object):
 
 class ExperimentController(object):
     """
-    .. class:: Class Args :
-      
-        :param exp_id: Human readable identifier for the experiment scenario. 
-        :type exp_id: str
-
     .. note::
 
     An experiment, or scenario, is defined by a concrete set of resources,
@@ -162,7 +166,8 @@ class ExperimentController(object):
         return ec
 
     def __init__(self, exp_id = None, local_dir = None, persist = False,
-            add_node_callback = None, add_edge_callback = None, **kwargs):
+            fm = None, add_node_callback = None, add_edge_callback = None, 
+            **kwargs):
         """ ExperimentController entity to model an execute a network 
         experiment.
         
@@ -177,6 +182,10 @@ class ExperimentController(object):
         completion at local_dir
         :type persist: bool
 
+        :param fm: FailureManager object. If None is given, the default 
+            FailureManager class will be used
+        :type fm: FailureManager
+
         :param add_node_callback: Callback to invoke for node instantiation
         when automatic topology creation mode is used 
         :type add_node_callback: function
@@ -238,7 +247,9 @@ class ExperimentController(object):
         self._stop = False
     
         # Entity in charge of managing system failures
-        self._fm = FailureManager(self)
+        if not fm:
+            self._fm = FailureManager()
+        self._fm.set_ec(self)
 
         # EC state
         self._state = ECState.RUNNING