cleanup and javadoc for remaining files in onos.core.intent.runtime

Change-Id: I04567ba3b2e70bb3f72da5a863306efe1a6063b6
diff --git a/src/main/java/net/onrc/onos/core/intent/runtime/IPathCalcRuntimeService.java b/src/main/java/net/onrc/onos/core/intent/runtime/IPathCalcRuntimeService.java
index b81dbab..802f244 100644
--- a/src/main/java/net/onrc/onos/core/intent/runtime/IPathCalcRuntimeService.java
+++ b/src/main/java/net/onrc/onos/core/intent/runtime/IPathCalcRuntimeService.java
@@ -8,11 +8,11 @@
 import net.onrc.onos.core.intent.IntentOperationList;
 
 /**
- * @author Toshio Koide (t-koide@onlab.us)
+ * Interface class used by PathCalcRuntimeModule class to operate intents.
  */
 public interface IPathCalcRuntimeService extends IFloodlightService {
     /**
-     * Add Application Intents.
+     * Adds Application Intents.
      *
      * @param appId the Application ID to use.
      * @param appIntents the Application Intents to add.
@@ -23,7 +23,7 @@
                 Collection<ApplicationIntent> appIntents);
 
     /**
-     * Remove Application Intents.
+     * Removes Application Intents.
      *
      * @param appId the Application ID to use.
      * @param intentIds the Application Intent IDs to remove.
@@ -33,18 +33,50 @@
                                             Collection<String> intentIds);
 
     /**
-     * Remove all Application Intents.
+     * Removes all Application Intents.
      *
      * @param appId the Application ID to use.
      * @return true on success, otherwise false.
      */
     public boolean removeAllApplicationIntents(final String appId);
 
+    /**
+     * Executes Application-level Intent operations.
+     * <p>
+     * IntentOperationList accepts ADD and REMOVE operations at the same time
+     * in order to update intents in one shot. It converts application-level
+     * intent operations into path-level intent operations, and send them to
+     * PlanCalcModule.
+     *
+     * @param list a list of intent operations
+     * @return the converted path-level intent operations
+     */
     public IntentOperationList executeIntentOperations(IntentOperationList list);
 
+    /**
+     * Retrieves application-level intents.
+     * <p>
+     * It returns IntentMap object. This object has listener to listen the
+     * additions, the removals and the status changes of intents.
+     *
+     * @return application-level intents.
+     */
     public IntentMap getHighLevelIntents();
 
+    /**
+     * Retrieves path-level intents.
+     * <p>
+     * It returns IntentMap object. This object has listener to listen the
+     * additions, the removals and the status changes of intents.
+     *
+     * @return path-level intents.
+     */
     public IntentMap getPathIntents();
 
+    /**
+     * Purges invalid intents.
+     * <p>
+     * It removes all uninstalled or failed application/path level intents.
+     */
     public void purgeIntents();
 }
diff --git a/src/main/java/net/onrc/onos/core/intent/runtime/IntentStateList.java b/src/main/java/net/onrc/onos/core/intent/runtime/IntentStateList.java
index 2b4946f..6103c64 100644
--- a/src/main/java/net/onrc/onos/core/intent/runtime/IntentStateList.java
+++ b/src/main/java/net/onrc/onos/core/intent/runtime/IntentStateList.java
@@ -7,23 +7,46 @@
 import java.util.Set;
 
 import net.onrc.onos.core.intent.Intent.IntentState;
+
+/**
+ * Used by PathCalcRuntimeModule and PlanInstallModule
+ * to notify path intents' state changes.
+ */
 public class IntentStateList {
     protected Map<String, IntentState> intentMap;
     public Set<Long> domainSwitchDpids;
 
+    /**
+     * Constructor to make new IntentStateList.
+     */
     public IntentStateList() {
         intentMap = new HashMap<String, IntentState>();
         domainSwitchDpids = new HashSet<Long>();
     }
 
+    /**
+     * Adds or modifies intent's state.
+     *
+     * @param id an intent ID for the state.
+     * @param state a state for the intent.
+     * @return the previous state, or null if there was no intents.
+     */
     public IntentState put(String id, IntentState state) {
         return intentMap.put(id, state);
     }
 
+    /**
+     * Returns a set of view of the intent states.
+     *
+     * @return a set of intent IDs and intent states.
+     */
     public Set<Entry<String, IntentState>> entrySet() {
         return intentMap.entrySet();
     }
 
+    /**
+     * Removes all of intent states from this object.
+     */
     public void clear() {
         intentMap.clear();
     }
diff --git a/src/main/java/net/onrc/onos/core/intent/runtime/PathCalcRuntime.java b/src/main/java/net/onrc/onos/core/intent/runtime/PathCalcRuntime.java
index e1b95e2..03e23c5 100644
--- a/src/main/java/net/onrc/onos/core/intent/runtime/PathCalcRuntime.java
+++ b/src/main/java/net/onrc/onos/core/intent/runtime/PathCalcRuntime.java
@@ -24,18 +24,25 @@
 import org.slf4j.LoggerFactory;
 
 /**
- * @author Toshio Koide (t-koide@onlab.us)
+ * The runtime used by PathCalcRuntimeModule class.
+ * <p>
+ * It calculates shortest-path and constrained-shortest-path.
  */
 public class PathCalcRuntime implements IFloodlightService {
     private Topology topology;
     private static final Logger log = LoggerFactory.getLogger(PathCalcRuntime.class);
 
+    /**
+     * Constructor.
+     *
+     * @param topology a topology object to use for the path calculation.
+     */
     public PathCalcRuntime(Topology topology) {
         this.topology = topology;
     }
 
     /**
-     * calculate shortest-path and constrained-shortest-path intents into low-level path intents.
+     * Calculates shortest-path and constrained-shortest-path intents into low-level path intents.
      *
      * @param intentOpList IntentOperationList having instances of ShortestPathIntent/ConstrainedShortestPathIntent
      * @param pathIntents  a set of current low-level intents
diff --git a/src/main/java/net/onrc/onos/core/intent/runtime/PathCalcRuntimeModule.java b/src/main/java/net/onrc/onos/core/intent/runtime/PathCalcRuntimeModule.java
index 2f820a0..bfbaa30 100644
--- a/src/main/java/net/onrc/onos/core/intent/runtime/PathCalcRuntimeModule.java
+++ b/src/main/java/net/onrc/onos/core/intent/runtime/PathCalcRuntimeModule.java
@@ -50,12 +50,21 @@
 import org.slf4j.LoggerFactory;
 
 /**
- * @author Toshio Koide (t-koide@onlab.us)
+ * The PathCalcRuntimeModule contains the PathCalcRuntime and PersistIntent.
+ * <p>
+ * It is responsible for converting operations for application level intents
+ * into operations for path level intents and send the converted operations
+ * to PlanCalcRuntimeModule in order to calculate flow entries and install them.
  */
 public class PathCalcRuntimeModule implements IFloodlightModule,
                                     IPathCalcRuntimeService,
                                     ITopologyListener,
                                     IEventChannelListener<Long, IntentStateList> {
+
+    /**
+     * Logging object for performance measurement.
+     * TODO: merge this into measurement framework
+     */
     static class PerfLog {
         private String step;
         private long time;
@@ -70,6 +79,10 @@
         }
     }
 
+    /**
+     * Formatted logger for performance measurement.
+     * TODO: merge this into measurement framework
+     */
     static class PerfLogger {
         private LinkedList<PerfLog> logData = new LinkedList<>();
 
@@ -198,6 +211,13 @@
     // private methods
     // ================================================================================
 
+    /**
+     * Creates operations (IntentOperationList) for Application-level
+     * intents that should be rerouted because of topology change,
+     * and execute the created operations.
+     *
+     * @param oldPaths a list of invalid path intents (which should be rerouted)
+     */
     private void reroutePaths(Collection<Intent> oldPaths) {
         if (oldPaths == null || oldPaths.isEmpty()) {
             return;
@@ -227,11 +247,86 @@
         executeIntentOperations(reroutingOperation);
     }
 
+    /**
+     * Checks whether the entire path's flow entries are installed or not.
+     *
+     * @param pathIntent : The pathIntent to be checked
+     * @param installedDpids : The dpids installed on one ONOS instance
+     * @return The result of whether a pathIntent has been installed or not.
+     */
+    private boolean isFlowInstalled(PathIntent pathIntent, Set<Long> installedDpids) {
+        String pathIntentId = pathIntent.getId();
+
+        if (intentInstalledMap.containsKey(pathIntentId)) {
+            if (!installedDpids.isEmpty()) {
+                intentInstalledMap.get(pathIntentId).addAll(installedDpids);
+            }
+        } else {
+            // This is the creation of an entry.
+            intentInstalledMap.put(pathIntentId, installedDpids);
+        }
+
+        Set<Long> allSwitchesForPath = new HashSet<Long>();
+        ShortestPathIntent spfIntent = (ShortestPathIntent) pathIntent.getParentIntent();
+
+        for (LinkEvent linkEvent : pathIntent.getPath()) {
+            long sw = linkEvent.getSrc().getDpid();
+            allSwitchesForPath.add(sw);
+        }
+        allSwitchesForPath.add(spfIntent.getDstSwitchDpid());
+
+        if (log.isDebugEnabled()) {
+            log.debug("checking flow installation. ID:{}, dpids:{}, installed:{}",
+                    pathIntentId,
+                    allSwitchesForPath,
+                    intentInstalledMap.get(pathIntentId));
+        }
+
+        if (allSwitchesForPath.equals(intentInstalledMap.get(pathIntentId))) {
+            intentInstalledMap.remove(pathIntentId);
+            return true;
+        }
+
+        return false;
+    }
+
+    /**
+     * Enumerates switch dpids along the specified path and inside the specified domain.
+     *
+     * @param pathIntent the path for enumeration
+     * @param domainSwitchDpids a set of the domain switch dpids
+     * @return a set of switch dpids along the specified path and inside the specified domain
+     */
+    private Set<Long> calcInstalledDpids(PathIntent pathIntent, Set<Long> domainSwitchDpids) {
+        Set<Long> allSwitchesForPath = new HashSet<Long>();
+        ShortestPathIntent spfIntent = (ShortestPathIntent) pathIntent.getParentIntent();
+
+        for (LinkEvent linkEvent : pathIntent.getPath()) {
+            long sw = linkEvent.getSrc().getDpid();
+
+            if (domainSwitchDpids.contains(sw)) {
+                allSwitchesForPath.add(sw);
+            }
+        }
+
+        if (domainSwitchDpids.contains(spfIntent.getDstSwitchDpid())) {
+            allSwitchesForPath.add(spfIntent.getDstSwitchDpid());
+        }
+
+        if (log.isTraceEnabled()) {
+            log.trace("All switches for a path {}, domain switch dpids {}", allSwitchesForPath, domainSwitchDpids);
+        }
+
+        return allSwitchesForPath;
+    }
 
     // ================================================================================
     // IFloodlightModule implementations
     // ================================================================================
 
+    /**
+     * {@inheritDoc}
+     */
     @Override
     public Collection<Class<? extends IFloodlightService>> getModuleServices() {
         Collection<Class<? extends IFloodlightService>> l = new ArrayList<>(1);
@@ -239,6 +334,9 @@
         return l;
     }
 
+    /**
+     * {@inheritDoc}
+     */
     @Override
     public Map<Class<? extends IFloodlightService>, IFloodlightService> getServiceImpls() {
         Map<Class<? extends IFloodlightService>, IFloodlightService> m = new HashMap<>();
@@ -246,6 +344,9 @@
         return m;
     }
 
+    /**
+     * {@inheritDoc}
+     */
     @Override
     public Collection<Class<? extends IFloodlightService>> getModuleDependencies() {
         Collection<Class<? extends IFloodlightService>> l = new ArrayList<>(2);
@@ -255,6 +356,9 @@
         return l;
     }
 
+    /**
+     * {@inheritDoc}
+     */
     @Override
     public void init(FloodlightModuleContext context) throws FloodlightModuleException {
         datagridService = context.getServiceImpl(IDatagridService.class);
@@ -263,6 +367,9 @@
         restApi = context.getServiceImpl(IRestApiService.class);
     }
 
+    /**
+     * {@inheritDoc}
+     */
     @Override
     public void startUp(FloodlightModuleContext context) {
         highLevelIntents = new IntentMap();
@@ -282,11 +389,7 @@
     // ======================================================================
 
     /**
-     * Add Application Intents.
-     *
-     * @param appId the Application ID to use.
-     * @param appIntents the Application Intents to add.
-     * @return true on success, otherwise false.
+     * {@inheritDoc}
      */
     @Override
     public boolean addApplicationIntents(
@@ -349,11 +452,7 @@
     }
 
     /**
-     * Remove Application Intents.
-     *
-     * @param appId the Application ID to use.
-     * @param intentIds the Application Intent IDs to remove.
-     * @return true on success, otherwise false.
+     * {@inheritDoc}
      */
     @Override
     public boolean removeApplicationIntents(final String appId,
@@ -395,10 +494,7 @@
     }
 
     /**
-     * Remove all Application Intents.
-     *
-     * @param appId the Application ID to use.
-     * @return true on success, otherwise false.
+     * {@inheritDoc}
      */
     @Override
     public boolean removeAllApplicationIntents(final String appId) {
@@ -434,6 +530,9 @@
         return true;
     }
 
+    /**
+     * {@inheritDoc}
+     */
     @Override
     public IntentOperationList executeIntentOperations(IntentOperationList list) {
 
@@ -513,16 +612,25 @@
         }
     }
 
+    /**
+     * {@inheritDoc}
+     */
     @Override
     public IntentMap getHighLevelIntents() {
         return highLevelIntents;
     }
 
+    /**
+     * {@inheritDoc}
+     */
     @Override
     public IntentMap getPathIntents() {
         return pathIntents;
     }
 
+    /**
+     * {@inheritDoc}
+     */
     @Override
     public void purgeIntents() {
         highLevelIntents.purge();
@@ -534,6 +642,9 @@
     // ================================================================================
 
     // CHECKSTYLE:OFF suppress warning about too many parameters
+    /**
+     * {@inheritDoc}
+     */
     @Override
     public void topologyEvents(Collection<SwitchEvent> addedSwitchEvents,
                                    Collection<SwitchEvent> removedSwitchEvents,
@@ -609,16 +720,25 @@
     // IEventChannelListener implementations
     // ================================================================================
 
+    /**
+     * {@inheritDoc}
+     */
     @Override
     public void entryAdded(IntentStateList value) {
         entryUpdated(value);
     }
 
+    /**
+     * {@inheritDoc}
+     */
     @Override
     public void entryRemoved(IntentStateList value) {
         // do nothing
     }
 
+    /**
+     * {@inheritDoc}
+     */
     @SuppressWarnings("fallthrough")
     @Override
     public void entryUpdated(IntentStateList value) {
@@ -712,70 +832,4 @@
         }
         executeIntentOperations(opList);
     }
-
-    /***
-     * This function is to check whether the entire path's flow entries are installed or not.
-     *
-     * @param pathIntent : The pathIntent to be checked
-     * @param installedDpids : The dpids installed on one ONOS instance
-     * @return The result of whether a pathIntent has been installed or not.
-     */
-    private boolean isFlowInstalled(PathIntent pathIntent, Set<Long> installedDpids) {
-        String pathIntentId = pathIntent.getId();
-
-        if (intentInstalledMap.containsKey(pathIntentId)) {
-            if (!installedDpids.isEmpty()) {
-                intentInstalledMap.get(pathIntentId).addAll(installedDpids);
-            }
-        } else {
-            // This is the creation of an entry.
-            intentInstalledMap.put(pathIntentId, installedDpids);
-        }
-
-        Set<Long> allSwitchesForPath = new HashSet<Long>();
-        ShortestPathIntent spfIntent = (ShortestPathIntent) pathIntent.getParentIntent();
-
-        for (LinkEvent linkEvent : pathIntent.getPath()) {
-            long sw = linkEvent.getSrc().getDpid();
-            allSwitchesForPath.add(sw);
-        }
-        allSwitchesForPath.add(spfIntent.getDstSwitchDpid());
-
-        if (log.isDebugEnabled()) {
-            log.debug("checking flow installation. ID:{}, dpids:{}, installed:{}",
-                    pathIntentId,
-                    allSwitchesForPath,
-                    intentInstalledMap.get(pathIntentId));
-        }
-
-        if (allSwitchesForPath.equals(intentInstalledMap.get(pathIntentId))) {
-            intentInstalledMap.remove(pathIntentId);
-            return true;
-        }
-
-        return false;
-    }
-
-    private Set<Long> calcInstalledDpids(PathIntent pathIntent, Set<Long> domainSwitchDpids) {
-        Set<Long> allSwitchesForPath = new HashSet<Long>();
-        ShortestPathIntent spfIntent = (ShortestPathIntent) pathIntent.getParentIntent();
-
-        for (LinkEvent linkEvent : pathIntent.getPath()) {
-            long sw = linkEvent.getSrc().getDpid();
-
-            if (domainSwitchDpids.contains(sw)) {
-                allSwitchesForPath.add(sw);
-            }
-        }
-
-        if (domainSwitchDpids.contains(spfIntent.getDstSwitchDpid())) {
-            allSwitchesForPath.add(spfIntent.getDstSwitchDpid());
-        }
-
-        if (log.isTraceEnabled()) {
-            log.trace("All switches for a path {}, domain switch dpids {}", allSwitchesForPath, domainSwitchDpids);
-        }
-
-        return allSwitchesForPath;
-    }
 }
diff --git a/src/main/java/net/onrc/onos/core/intent/runtime/PersistIntent.java b/src/main/java/net/onrc/onos/core/intent/runtime/PersistIntent.java
index 9a9d59c..d1076ed 100644
--- a/src/main/java/net/onrc/onos/core/intent/runtime/PersistIntent.java
+++ b/src/main/java/net/onrc/onos/core/intent/runtime/PersistIntent.java
@@ -21,7 +21,9 @@
 import com.esotericsoftware.kryo.io.Output;
 
 /**
- * @author nickkaranatsios
+ * The module used by PathCalcRuntimeModule class.
+ * <p>
+ * It persists intent operations into persistent storage.
  */
 public class PersistIntent {
     private static final Logger log = LoggerFactory.getLogger(PersistIntent.class);
@@ -37,7 +39,11 @@
     private long rangeEnd;
     private IdBlock idBlock = null;
 
-
+    /**
+     * Constructor.
+     *
+     * @param controllerRegistry the Registry Service to use.
+     */
     public PersistIntent(final IControllerRegistryService controllerRegistry) {
         this.controllerRegistry = controllerRegistry;
         table = DataStoreClient.getClient().getTable(INTENT_JOURNAL);
@@ -47,6 +53,21 @@
         kryo = new KryoFactory(1).newKryo();
     }
 
+    private long getNextBlock() {
+        // XXX This method is not thread safe, may lose allocated IdBlock
+        idBlock = controllerRegistry.allocateUniqueIdBlock(range);
+        nextId = new AtomicLong(idBlock.getStart());
+        rangeEnd = idBlock.getEnd();
+        return nextId.get();
+    }
+
+    /**
+     * Provides the unique key for persisting.
+     * <p>
+     * This key is necessary for persistIfLeader() method.
+     *
+     * @return a key for persisting.
+     */
     public long getKey() {
         long key;
         if (idBlock == null) {
@@ -60,14 +81,13 @@
         return key;
     }
 
-    private long getNextBlock() {
-        // XXX This method is not thread safe, may lose allocated IdBlock
-        idBlock = controllerRegistry.allocateUniqueIdBlock(range);
-        nextId = new AtomicLong(idBlock.getStart());
-        rangeEnd = idBlock.getEnd();
-        return nextId.get();
-    }
-
+    /**
+     * Persist intent operations into persistent storage only if this instance was a leader.
+     *
+     * @param key a unique key
+     * @param operations intent operations
+     * @return true if succeeded, otherwise false.
+     */
     public boolean persistIfLeader(long key, IntentOperationList operations) {
         boolean leader = true;
         boolean ret = false;