Checkstyle enforcer
[controller.git] / opendaylight / forwardingrulesmanager / implementation / src / main / java / org / opendaylight / controller / forwardingrulesmanager / internal / ForwardingRulesManagerImpl.java
index fe2cdc473822628859ff73ed1ba13b7095036f04..db1186e6b753a88e46ff9d2913f801d827764f01 100644 (file)
@@ -135,7 +135,7 @@ public class ForwardingRulesManagerImpl implements IForwardingRulesManager,
      * Adds a flow entry onto the network node It runs various validity checks
      * and derive the final container flows merged entries that will be
      * attempted to be installed
-     * 
+     *
      * @param flowEntry
      *            the original flow entry application requested to add
      * @param async
@@ -144,7 +144,7 @@ public class ForwardingRulesManagerImpl implements IForwardingRulesManager,
      *          will contain the unique id assigned to this request
      */
     private Status addEntry(FlowEntry flowEntry, boolean async) {
-        
+
         // Sanity Check
         if (flowEntry == null || flowEntry.getNode() == null) {
             String msg = "Invalid FlowEntry";
@@ -209,7 +209,7 @@ public class ForwardingRulesManagerImpl implements IForwardingRulesManager,
                  * complication for now and assume we will always deal with
                  * one flow only per request
                  */
-                succeded = ret;   
+                succeded = ret;
             } else {
                 error = ret;
                 log.warn("Failed to install the entry: {}. The failure is: {}",
@@ -228,7 +228,7 @@ public class ForwardingRulesManagerImpl implements IForwardingRulesManager,
      * flow entry is congruent with all the N container flows, then the output
      * install entry list will contain N entries. If the output list is empty,
      * it means the passed flow entry conflicts with all the container flows.
-     * 
+     *
      * @param cFlowList
      *            The list of container flows
      * @return the list of container flow merged entries good to be installed on
@@ -260,7 +260,7 @@ public class ForwardingRulesManagerImpl implements IForwardingRulesManager,
     /**
      * Modify a flow entry with a new one It runs various validity check and
      * derive the final container flows merged flow entries to work with
-     * 
+     *
      * @param currentFlowEntry
      * @param newFlowEntry
      * @param async
@@ -335,13 +335,13 @@ public class ForwardingRulesManagerImpl implements IForwardingRulesManager,
          * This is only possible when the new entry and current entry have
          * different match. In this scenario the modification would ultimately
          * be handled as a remove and add operations in the protocol plugin.
-         * 
+         *
          * Also, if any of the new flow entries would clash with an existing
          * one, we cannot proceed with the modify operation, because it would
          * fail for some entries and leave stale entries on the network node.
          * Modify path can be taken only if it can be performed completely, for
          * all entries.
-         * 
+         *
          * So, for the above two cases, to simplify, let's decouple the modify
          * in: 1) remove current entries 2) install new entries
          */
@@ -384,7 +384,7 @@ public class ForwardingRulesManagerImpl implements IForwardingRulesManager,
              * (and might be wrong) that the same container flows that were
              * satisfied by the current entries are the same that are satisfied
              * by the new entries. Let's take the risk for now.
-             * 
+             *
              * Note: modification has to be complete. If any entry modification
              * fails, we need to stop, restore the already modified entries, and
              * declare failure.
@@ -440,7 +440,7 @@ public class ForwardingRulesManagerImpl implements IForwardingRulesManager,
      * This is the function that modifies the final container flows merged
      * entries on the network node and update the database. It expects that all
      * the validity checks are passed
-     * 
+     *
      * @param currentEntries
      * @param newEntries
      * @param async
@@ -451,7 +451,7 @@ public class ForwardingRulesManagerImpl implements IForwardingRulesManager,
     private Status modifyEntryInternal(FlowEntryInstall currentEntries,
             FlowEntryInstall newEntries, boolean async) {
         // Modify the flow on the network node
-        Status status = (async)? 
+        Status status = (async)?
                 programmer.modifyFlowAsync(currentEntries.getNode(),
                         currentEntries.getInstall().getFlow(), newEntries.getInstall()
                                 .getFlow()) :
@@ -481,7 +481,7 @@ public class ForwardingRulesManagerImpl implements IForwardingRulesManager,
     /**
      * Remove a flow entry. If the entry is not present in the software view
      * (entry or node not present), it return successfully
-     * 
+     *
      * @param flowEntry
      *          the flow entry to remove
      * @param async
@@ -489,7 +489,7 @@ public class ForwardingRulesManagerImpl implements IForwardingRulesManager,
      * @return the status of this request. In case of asynchronous call, it
      *          will contain the unique id assigned to this request
      */
-    private Status removeEntry(FlowEntry flowEntry, boolean async) {
+    private synchronized Status removeEntry(FlowEntry flowEntry, boolean async) {
         Status error = new Status(null, null);
 
         // Sanity Check
@@ -554,7 +554,7 @@ public class ForwardingRulesManagerImpl implements IForwardingRulesManager,
      * This is the function that removes the final container flows merged entry
      * from the network node and update the database. It expects that all the
      * validity checks are passed
-     * 
+     *
      * @param entry
      *            the flow entry to remove
      * @param async
@@ -572,7 +572,7 @@ public class ForwardingRulesManagerImpl implements IForwardingRulesManager,
                         .getInstall().getFlow()) :
                 programmer.removeFlow(entry.getNode(), entry
                         .getInstall().getFlow());
+
 
         if (!status.isSuccess()) {
             log.warn(
@@ -593,7 +593,7 @@ public class ForwardingRulesManagerImpl implements IForwardingRulesManager,
      * on the network node and updates the database. It expects that all the
      * validity and conflict checks are passed. That means it does not check
      * whether this flow would conflict or overwrite an existing one.
-     * 
+     *
      * @param entry
      *            the flow entry to install
      * @param async
@@ -604,9 +604,9 @@ public class ForwardingRulesManagerImpl implements IForwardingRulesManager,
     private Status addEntriesInternal(FlowEntryInstall entry, boolean async) {
         // Install the flow on the network node
         Status status = (async)?
-                programmer.addFlow(entry.getNode(), entry.getInstall()
-                        .getFlow()) :
                 programmer.addFlowAsync(entry.getNode(), entry.getInstall()
+                        .getFlow()) :
+                programmer.addFlow(entry.getNode(), entry.getInstall()
                             .getFlow());
 
 
@@ -631,7 +631,7 @@ public class ForwardingRulesManagerImpl implements IForwardingRulesManager,
      * means that if the function returns true, the passed flow entry is
      * congruent with at least one container flow, hence it is good to be
      * installed on this container.
-     * 
+     *
      * @param flowEntry
      * @return true if flow conflicts with all the container flows, false
      *         otherwise
@@ -667,7 +667,7 @@ public class ForwardingRulesManagerImpl implements IForwardingRulesManager,
     /*
      * Update the node mapped flows database
      */
-    private void updateNodeFlowsDB(FlowEntryInstall flowEntries, boolean add) {
+    private synchronized void updateNodeFlowsDB(FlowEntryInstall flowEntries, boolean add) {
         Node node = flowEntries.getNode();
 
         Set<FlowEntryInstall> flowEntrylist = this.nodeFlows.get(node);
@@ -751,7 +751,7 @@ public class ForwardingRulesManagerImpl implements IForwardingRulesManager,
      * entry is effectively present in the local database
      */
     @SuppressWarnings("unused")
-    private Status removeEntry(Node node, String flowName) {
+    private synchronized Status removeEntry(Node node, String flowName) {
         FlowEntryInstall target = null;
 
         // Find in database
@@ -837,7 +837,7 @@ public class ForwardingRulesManagerImpl implements IForwardingRulesManager,
         }
         return status;
     }
-    
+
     @Override
     public Status modifyFlowEntry(FlowEntry currentFlowEntry,
             FlowEntry newFlowEntry) {
@@ -904,17 +904,17 @@ public class ForwardingRulesManagerImpl implements IForwardingRulesManager,
             return modifyFlowEntryAsync(currentFlowEntries.getOriginal(),
                    newone);
         } else {
-            return installFlowEntry(newone);
+            return installFlowEntryAsync(newone);
         }
     }
 
-    
+
     /**
      * Try to find in the database if a Flow with the same Match and priority of
      * the passed one already exists for the specified network node. Flow,
      * priority and network node are all specified in the FlowEntry If found,
      * the respective FlowEntryInstall Object is returned
-     * 
+     *
      * @param flowEntry
      *            the FlowEntry to be tested against the ones installed
      * @param looseCheck
@@ -923,7 +923,7 @@ public class ForwardingRulesManagerImpl implements IForwardingRulesManager,
      * @return null if not found, otherwise the FlowEntryInstall which contains
      *         the existing flow entry
      */
-    private FlowEntryInstall findMatch(FlowEntry flowEntry, boolean looseCheck) {
+    private synchronized FlowEntryInstall findMatch(FlowEntry flowEntry, boolean looseCheck) {
         Flow flow = flowEntry.getFlow();
         Match match = flow.getMatch();
         short priority = flow.getPriority();
@@ -953,7 +953,7 @@ public class ForwardingRulesManagerImpl implements IForwardingRulesManager,
      * merged flow may conflict with an existing old container flows merged flow
      * on the network node
      */
-    private void updateFlowsContainerFlow() {
+    private synchronized void updateFlowsContainerFlow() {
         List<FlowEntryInstall> oldCouples = new ArrayList<FlowEntryInstall>();
         List<FlowEntry> toReinstall = new ArrayList<FlowEntry>();
         for (Entry<Node, Set<FlowEntryInstall>> entry : this.nodeFlows
@@ -1041,19 +1041,17 @@ public class ForwardingRulesManagerImpl implements IForwardingRulesManager,
 
     @Override
     public List<FlowEntry> getFlowEntriesForGroup(String policyName) {
-        List<FlowEntry> list = null;
+        List<FlowEntry> list = new ArrayList<FlowEntry>();
         if (this.groupFlows != null && this.groupFlows.containsKey(policyName)) {
-            list = new ArrayList<FlowEntry>();
             for (FlowEntryInstall entries : groupFlows.get(policyName)) {
                 list.add(entries.getOriginal());
             }
-            return new ArrayList<FlowEntry>();
         }
         return list;
     }
 
     @Override
-    public void addOutputPort(Node node, String flowName,
+    public synchronized void addOutputPort(Node node, String flowName,
             List<NodeConnector> portList) {
 
         Set<FlowEntryInstall> flowEntryList = this.nodeFlows.get(node);
@@ -1083,7 +1081,7 @@ public class ForwardingRulesManagerImpl implements IForwardingRulesManager,
     }
 
     @Override
-    public void removeOutputPort(Node node, String flowName,
+    public synchronized void removeOutputPort(Node node, String flowName,
             List<NodeConnector> portList) {
 
         Set<FlowEntryInstall> flowEntryList = this.nodeFlows.get(node);
@@ -1118,7 +1116,7 @@ public class ForwardingRulesManagerImpl implements IForwardingRulesManager,
      * This function assumes the target flow has only one output port
      */
     @Override
-    public void replaceOutputPort(Node node, String flowName,
+    public synchronized void replaceOutputPort(Node node, String flowName,
             NodeConnector outPort) {
         FlowEntry currentFlowEntry = null;
         FlowEntry newFlowEntry = null;
@@ -1165,7 +1163,7 @@ public class ForwardingRulesManagerImpl implements IForwardingRulesManager,
     }
 
     @Override
-    public NodeConnector getOutputPort(Node node, String flowName) {
+    public synchronized NodeConnector getOutputPort(Node node, String flowName) {
         Set<FlowEntryInstall> flowEntryList = this.nodeFlows.get(node);
 
         for (FlowEntryInstall flow : flowEntryList) {
@@ -1411,9 +1409,9 @@ public class ForwardingRulesManagerImpl implements IForwardingRulesManager,
          * multiple entry configuration (PortGroup) and hardware installation is
          * NOT done directly on this event. 3. The User prefers to retain the
          * configuration in Controller and skip hardware installation.
-         * 
+         *
          * Hence it is safe to update the StaticFlow DB at this point.
-         * 
+         *
          * Note : For the case of PortGrouping, it is essential to have this DB
          * populated before the PortGroupListeners can query for the DB
          * triggered using portGroupChanged event...
@@ -1926,7 +1924,7 @@ public class ForwardingRulesManagerImpl implements IForwardingRulesManager,
 
     /**
      * Remove from the databases all the flows installed on the node
-     * 
+     *
      * @param node
      */
     private synchronized void cleanDatabaseForNode(Node node) {
@@ -2212,7 +2210,7 @@ public class ForwardingRulesManagerImpl implements IForwardingRulesManager,
     /**
      * Function called by the dependency manager when all the required
      * dependencies are satisfied
-     * 
+     *
      */
     void init() {
         frmAware = Collections
@@ -2247,7 +2245,7 @@ public class ForwardingRulesManagerImpl implements IForwardingRulesManager,
      * Function called by the dependency manager when at least one dependency
      * become unsatisfied or when the component is shutting down because for
      * example bundle is being stopped.
-     * 
+     *
      */
     void destroy() {
         destroyCaches();
@@ -2256,7 +2254,7 @@ public class ForwardingRulesManagerImpl implements IForwardingRulesManager,
     /**
      * Function called by dependency manager after "init ()" is called and after
      * the services provided by the class are registered in the service registry
-     * 
+     *
      */
     void start() {
         /*
@@ -2272,7 +2270,7 @@ public class ForwardingRulesManagerImpl implements IForwardingRulesManager,
      * Function called by the dependency manager before the services exported by
      * the component are unregistered, this will be followed by a "destroy ()"
      * calls
-     * 
+     *
      */
     void stop() {
     }
@@ -2537,14 +2535,14 @@ public class ForwardingRulesManagerImpl implements IForwardingRulesManager,
     }
 
     @Override
-    public void flowErrorReported(Node node, long rid, Object err) {
+    public synchronized void flowErrorReported(Node node, long rid, Object err) {
         log.trace("Got error {} for message rid {} from node {}",
                 new Object[] {err, rid, node });
         /*
          *  If this was for a flow install, remove the corresponding entry
          *  from the software view. If it was a Looking for the rid going through the
-         *  software database. 
-         *  TODO: A more efficient rid <->  FlowEntryInstall mapping will 
+         *  software database.
+         *  TODO: A more efficient rid <->  FlowEntryInstall mapping will
          *  have to be added in future
          */
         Set<FlowEntryInstall> entries = nodeFlows.get(node);
@@ -2561,7 +2559,7 @@ public class ForwardingRulesManagerImpl implements IForwardingRulesManager,
                 this.updateLocalDatabase(target, false);
             }
         }
-        
+
         // Notify listeners
         if (frmAware != null) {
             synchronized (frmAware) {
@@ -2575,12 +2573,19 @@ public class ForwardingRulesManagerImpl implements IForwardingRulesManager,
             }
         }
     }
-    
+
     @Override
-    public void solicitStatusResponse(Node node) {
+    public Status solicitStatusResponse(Node node, boolean blocking) {
+        Status rv = new Status(StatusCode.INTERNALERROR);
+
         if (this.programmer != null) {
-            programmer.sendBarrierMessage(node);
-        }        
-    }
+            if (blocking) {
+                rv = programmer.syncSendBarrierMessage(node);
+            } else {
+                rv = programmer.asyncSendBarrierMessage(node);
+            }
+        }
 
+        return rv;
+    }
 }