Merge "Fix Plugin execution not covered in Eclipse for config subsystem"
authorEd Warnicke <eaw@cisco.com>
Fri, 7 Feb 2014 06:10:44 +0000 (06:10 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Fri, 7 Feb 2014 06:10:44 +0000 (06:10 +0000)
opendaylight/configuration/api/src/main/java/org/opendaylight/controller/configuration/ConfigurationObject.java
opendaylight/forwardingrulesmanager/implementation/src/main/java/org/opendaylight/controller/forwardingrulesmanager/internal/ForwardingRulesManager.java
opendaylight/networkconfiguration/neutron/src/main/java/org/opendaylight/controller/networkconfig/neutron/NeutronSubnet.java
opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/core/internal/Controller.java

index 80aed17914d3fe9f77373de2dd32a02a9e2bcac3..720dc7b2344133420a0acb8fedd0e1841c9cd07c 100644 (file)
@@ -12,7 +12,7 @@ import java.io.Serializable;
 
 public abstract class ConfigurationObject implements Serializable {
     private static final long serialVersionUID = 1L;
-    private static final String DEFAULT_REGEX = "^[\\w-\\+\\*\\/\\.\\(\\)\\[\\]\\@\\|]{1,256}$";
+    private static final String DEFAULT_REGEX = "^[\\w-=\\+\\*\\/\\.\\(\\)\\[\\]\\@\\|\\:]{1,256}$";
     private static final String REGEX_PROP_NAME = "resourceNameRegularExpression";
     private static String regex;
 
index bce7dd30ba59de6c9707062f3fdeaf9f23a8141d..b94103fb1c7c9233bb417e93cc74d42bbef498e7 100644 (file)
@@ -331,7 +331,7 @@ public class ForwardingRulesManager implements
         for (FlowEntryInstall installEntry : toInstallSafe) {
 
             // Install and update database
-            Status ret = addEntriesInternal(installEntry, async);
+            Status ret = addEntryInternal(installEntry, async);
 
             if (ret.isSuccess()) {
                 oneSucceded = true;
@@ -494,7 +494,7 @@ public class ForwardingRulesManager implements
             }
             // Install new entries
             for (FlowEntryInstall newEntry : toInstallSafe) {
-                succeeded = this.addEntriesInternal(newEntry, async);
+                succeeded = this.addEntryInternal(newEntry, async);
             }
         } else {
             /*
@@ -554,7 +554,9 @@ public class ForwardingRulesManager implements
     /**
      * 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
+     * the validity checks are passed.
+     * This function is supposed to be called only on the controller on which
+     * the IFRM call is executed.
      *
      * @param currentEntries
      * @param newEntries
@@ -564,13 +566,13 @@ public class ForwardingRulesManager implements
      *         contain the unique id assigned to this request
      */
     private Status modifyEntryInternal(FlowEntryInstall currentEntries, FlowEntryInstall newEntries, boolean async) {
+        Status status = new Status(StatusCode.UNDEFINED);
         FlowEntryDistributionOrderFutureTask futureStatus =
                 distributeWorkOrder(currentEntries, newEntries, UpdateType.CHANGED);
         if (futureStatus != null) {
-            Status retStatus = new Status(StatusCode.UNDEFINED);
             try {
-                retStatus = futureStatus.get();
-                if (retStatus.getCode()
+                status = futureStatus.get();
+                if (status.getCode()
                         .equals(StatusCode.TIMEOUT)) {
                     // A timeout happened, lets cleanup the workMonitor
                     workMonitor.remove(futureStatus.getOrder());
@@ -580,30 +582,31 @@ public class ForwardingRulesManager implements
             } catch (ExecutionException e) {
                 log.error("", e);
             }
-            return retStatus;
         } else {
             // Modify the flow on the network node
-            Status status = async ? programmer.modifyFlowAsync(currentEntries.getNode(), currentEntries.getInstall()
-                    .getFlow(), newEntries.getInstall()
-                    .getFlow()) : programmer.modifyFlow(currentEntries.getNode(), currentEntries.getInstall()
-                    .getFlow(), newEntries.getInstall()
-                    .getFlow());
+            status = modifyEntryInHw(currentEntries, newEntries, async);
+        }
 
-            if (!status.isSuccess()) {
-                log.trace("SDN Plugin failed to program the flow: {}. The failure is: {}", newEntries.getInstall(),
-                        status.getDescription());
-                return status;
-            }
+        if (!status.isSuccess()) {
+            log.trace("{} SDN Plugin failed to program the flow: {}. The failure is: {}",
+                    (futureStatus != null) ? "Remote" : "Local", newEntries.getInstall(), status.getDescription());
+            return status;
+        }
 
-            log.trace("Modified {} => {}", currentEntries.getInstall(), newEntries.getInstall());
+        log.trace("Modified {} => {}", currentEntries.getInstall(), newEntries.getInstall());
 
-            // Update DB
-            newEntries.setRequestId(status.getRequestId());
-            updateSwViews(currentEntries, false);
-            updateSwViews(newEntries, true);
+        // Update DB
+        newEntries.setRequestId(status.getRequestId());
+        updateSwViews(currentEntries, false);
+        updateSwViews(newEntries, true);
 
-            return status;
-        }
+        return status;
+    }
+
+    private Status modifyEntryInHw(FlowEntryInstall currentEntries, FlowEntryInstall newEntries, boolean async) {
+        return async ? programmer.modifyFlowAsync(currentEntries.getNode(), currentEntries.getInstall().getFlow(),
+                newEntries.getInstall().getFlow()) : programmer.modifyFlow(currentEntries.getNode(), currentEntries
+                .getInstall().getFlow(), newEntries.getInstall().getFlow());
     }
 
     /**
@@ -672,6 +675,8 @@ public class ForwardingRulesManager implements
      * 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
+     * This function is supposed to be called only on the controller on which
+     * the IFRM call is executed.
      *
      * @param entry
      *            the flow entry to remove
@@ -681,13 +686,12 @@ public class ForwardingRulesManager implements
      *         contain the unique id assigned to this request
      */
     private Status removeEntryInternal(FlowEntryInstall entry, boolean async) {
+        Status status = new Status(StatusCode.UNDEFINED);
         FlowEntryDistributionOrderFutureTask futureStatus = distributeWorkOrder(entry, null, UpdateType.REMOVED);
         if (futureStatus != null) {
-            Status retStatus = new Status(StatusCode.UNDEFINED);
             try {
-                retStatus = futureStatus.get();
-                if (retStatus.getCode()
-                        .equals(StatusCode.TIMEOUT)) {
+                status = futureStatus.get();
+                if (status.getCode().equals(StatusCode.TIMEOUT)) {
                     // A timeout happened, lets cleanup the workMonitor
                     workMonitor.remove(futureStatus.getOrder());
                 }
@@ -696,28 +700,31 @@ public class ForwardingRulesManager implements
             } catch (ExecutionException e) {
                 log.error("", e);
             }
-            return retStatus;
         } else {
             // Mark the entry to be deleted (for CC just in case we fail)
             entry.toBeDeleted();
 
             // Remove from node
-            Status status = async ? programmer.removeFlowAsync(entry.getNode(), entry.getInstall()
-                    .getFlow()) : programmer.removeFlow(entry.getNode(), entry.getInstall()
-                    .getFlow());
-
-            if (!status.isSuccess()) {
-                log.trace("SDN Plugin failed to remove the flow: {}. The failure is: {}", entry.getInstall(),
-                        status.getDescription());
-                return status;
-            }
-            log.trace("Removed  {}", entry.getInstall());
-
-            // Update DB
-            updateSwViews(entry, false);
+            status = removeEntryInHw(entry, async);
+        }
 
+        if (!status.isSuccess()) {
+            log.trace("{} SDN Plugin failed to remove the flow: {}. The failure is: {}",
+                    (futureStatus != null) ? "Remote" : "Local", entry.getInstall(), status.getDescription());
             return status;
         }
+
+        log.trace("Removed  {}", entry.getInstall());
+
+        // Update DB
+        updateSwViews(entry, false);
+
+        return status;
+    }
+
+    private Status removeEntryInHw(FlowEntryInstall entry, boolean async) {
+        return async ? programmer.removeFlowAsync(entry.getNode(), entry.getInstall().getFlow()) : programmer
+                .removeFlow(entry.getNode(), entry.getInstall().getFlow());
     }
 
     /**
@@ -725,6 +732,8 @@ public class ForwardingRulesManager implements
      * 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.
+     * This function is supposed to be called only on the controller on which
+     * the IFRM call is executed.
      *
      * @param entry
      *            the flow entry to install
@@ -733,14 +742,13 @@ public class ForwardingRulesManager implements
      * @return the status of this request. In case of asynchronous call, it will
      *         contain the unique id assigned to this request
      */
-    private Status addEntriesInternal(FlowEntryInstall entry, boolean async) {
+    private Status addEntryInternal(FlowEntryInstall entry, boolean async) {
+        Status status = new Status(StatusCode.UNDEFINED);
         FlowEntryDistributionOrderFutureTask futureStatus = distributeWorkOrder(entry, null, UpdateType.ADDED);
         if (futureStatus != null) {
-            Status retStatus = new Status(StatusCode.UNDEFINED);
             try {
-                retStatus = futureStatus.get();
-                if (retStatus.getCode()
-                        .equals(StatusCode.TIMEOUT)) {
+                status = futureStatus.get();
+                if (status.getCode().equals(StatusCode.TIMEOUT)) {
                     // A timeout happened, lets cleanup the workMonitor
                     workMonitor.remove(futureStatus.getOrder());
                 }
@@ -749,27 +757,29 @@ public class ForwardingRulesManager implements
             } catch (ExecutionException e) {
                 log.error("", e);
             }
-            return retStatus;
         } else {
-            // Install the flow on the network node
-            Status status = async ? programmer.addFlowAsync(entry.getNode(), entry.getInstall()
-                    .getFlow()) : programmer.addFlow(entry.getNode(), entry.getInstall()
-                    .getFlow());
+            status = addEntryInHw(entry, async);
+        }
 
-            if (!status.isSuccess()) {
-                log.trace("SDN Plugin failed to program the flow: {}. The failure is: {}", entry.getInstall(),
-                        status.getDescription());
-                return status;
-            }
+        if (!status.isSuccess()) {
+            log.trace("{} SDN Plugin failed to program the flow: {}. The failure is: {}",
+                    (futureStatus != null) ? "Remote" : "Local", entry.getInstall(), status.getDescription());
+            return status;
+        }
+
+        log.trace("Added    {}", entry.getInstall());
 
-            log.trace("Added    {}", entry.getInstall());
+        // Update DB
+        entry.setRequestId(status.getRequestId());
+        updateSwViews(entry, true);
 
-            // Update DB
-            entry.setRequestId(status.getRequestId());
-            updateSwViews(entry, true);
+        return status;
+    }
 
-            return status;
-        }
+    private Status addEntryInHw(FlowEntryInstall entry, boolean async) {
+        // Install the flow on the network node
+        return async ? programmer.addFlowAsync(entry.getNode(), entry.getInstall().getFlow()) : programmer.addFlow(
+                entry.getNode(), entry.getInstall().getFlow());
     }
 
     /**
@@ -2526,13 +2536,13 @@ public class ForwardingRulesManager implements
                                         FlowEntryInstall feiNew = workOrder.get(fe);
                                         switch (fe.getUpType()) {
                                         case ADDED:
-                                            gotStatus = addEntriesInternal(feiCurrent, false);
+                                            gotStatus = addEntryInHw(feiCurrent, false);
                                             break;
                                         case CHANGED:
-                                            gotStatus = modifyEntryInternal(feiCurrent, feiNew, false);
+                                            gotStatus = modifyEntryInHw(feiCurrent, feiNew, false);
                                             break;
                                         case REMOVED:
-                                            gotStatus = removeEntryInternal(feiCurrent, false);
+                                            gotStatus = removeEntryInHw(feiCurrent, false);
                                             break;
                                         }
                                         // Remove the Order
index 11a1be21180db9f454cc1817ed55f762429d904d..6582d8c021d5f61de10ae6b221f1217fdd1d668f 100644 (file)
@@ -269,22 +269,26 @@ public class NeutronSubnet extends ConfigurationObject implements Serializable {
         }
         gatewayIPAssigned = false;
         dnsNameservers = new ArrayList<String>();
-        allocationPools = new ArrayList<NeutronSubnet_IPAllocationPool>();
-        hostRoutes = new ArrayList<NeutronSubnet_HostRoute>();
-        try {
-            SubnetUtils util = new SubnetUtils(cidr);
-            SubnetInfo info = util.getInfo();
-            if (gatewayIP == null) {
-                gatewayIP = info.getLowAddress();
-            }
-            if (allocationPools.size() < 1) {
-                NeutronSubnet_IPAllocationPool source =
-                    new NeutronSubnet_IPAllocationPool(info.getLowAddress(),
-                            info.getHighAddress());
-                allocationPools = source.splitPool(gatewayIP);
+        if (hostRoutes == null) {
+            hostRoutes = new ArrayList<NeutronSubnet_HostRoute>();
+        }
+        if (allocationPools == null) {
+            allocationPools = new ArrayList<NeutronSubnet_IPAllocationPool>();
+            try {
+                SubnetUtils util = new SubnetUtils(cidr);
+                SubnetInfo info = util.getInfo();
+                if (gatewayIP == null) {
+                    gatewayIP = info.getLowAddress();
+                }
+                if (allocationPools.size() < 1) {
+                    NeutronSubnet_IPAllocationPool source =
+                        new NeutronSubnet_IPAllocationPool(info.getLowAddress(),
+                                info.getHighAddress());
+                    allocationPools = source.splitPool(gatewayIP);
+                }
+            } catch (Exception e) {
+                return false;
             }
-        } catch (Exception e) {
-            return false;
         }
         return true;
     }
index 72ee7a679b010400e342047278136e2c73aa3a09..63dd0bc29ae03daefe8444991c00190dd28f9e06 100644 (file)
@@ -48,6 +48,7 @@ public class Controller implements IController, CommandProvider, IPluginInConnec
             .getLogger(Controller.class);
     private ControllerIO controllerIO;
     private Thread switchEventThread;
+    private volatile boolean shutdownSwitchEventThread;// default to false
     private ConcurrentHashMap<Long, ISwitch> switches;
     private PriorityBlockingQueue<SwitchEvent> switchEvents;
     // only 1 message listener per OFType
@@ -69,6 +70,12 @@ public class Controller implements IController, CommandProvider, IPluginInConnec
 
             while (true) {
                 try {
+                    if(shutdownSwitchEventThread) {
+                        // break out of the infinite loop
+                        // if you are shutting down
+                        logger.info("Switch Event Thread is shutting down");
+                        break;
+                    }
                     SwitchEvent ev = switchEvents.take();
                     SwitchEvent.SwitchEventType eType = ev.getEventType();
                     ISwitch sw = ev.getSwitch();
@@ -104,12 +111,14 @@ public class Controller implements IController, CommandProvider, IPluginInConnec
                         logger.error("Unknown switch event {}", eType.ordinal());
                     }
                 } catch (InterruptedException e) {
-                    switchEvents.clear();
-                    return;
+                    // nothing to do except retry
+                } catch (Exception e) {
+                    // log the exception and retry
+                    logger.warn("Exception in Switch Event Thread is {}" ,e);
                 }
             }
+            switchEvents.clear();
         }
-
     }
 
     /**
@@ -167,6 +176,7 @@ public class Controller implements IController, CommandProvider, IPluginInConnec
             ((SwitchHandler) entry.getValue()).stop();
             it.remove();
         }
+        shutdownSwitchEventThread = true;
         switchEventThread.interrupt();
         try {
             controllerIO.shutDown();