Merge "Fail toggle flow if port is no longer a part of slice"
authorAlessandro Boch <aboch@cisco.com>
Tue, 17 Sep 2013 23:38:32 +0000 (23:38 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Tue, 17 Sep 2013 23:38:32 +0000 (23:38 +0000)
1  2 
opendaylight/forwardingrulesmanager/implementation/src/main/java/org/opendaylight/controller/forwardingrulesmanager/internal/ForwardingRulesManager.java

index 58d23655cac5a17353989c5cfd36d71a7a14ea74,7feb7018ae65ee28ee3c4a0f769fb5660d4694f2..4e6818c3062511b01c9b8f73d3f5fa610c73134d
@@@ -1867,9 -1867,13 +1867,13 @@@ public class ForwardingRulesManager imp
              }
          }
          if (target != null) {
-             // Program the network node
-             Status status = (target.installInHw()) ? this.uninstallFlowEntry(target.getFlowEntry()) : this
-                     .installFlowEntry(target.getFlowEntry());
+             Status status = target.validate(container);
+             if (!status.isSuccess()) {
+                 log.warn(status.getDescription());
+                 return status;
+             }
+             status = (target.installInHw()) ? this.uninstallFlowEntry(target.getFlowEntry()) : this
+                                     .installFlowEntry(target.getFlowEntry());
              if (status.isSuccess()) {
                  // Update Configuration database
                  target.setStatus(SUCCESS);
          addStaticFlowInternal(allowARP, true); // skip validation on internal static flow name
      }
  
 +    /**
 +     * (non-Javadoc)
 +     *
 +     * @see org.opendaylight.controller.switchmanager.ISwitchManagerAware#modeChangeNotify(org.opendaylight.controller.sal.core.Node,
 +     *      boolean)
 +     *
 +     *      This method can be called from within the OSGi framework context,
 +     *      given the programming operation can take sometime, it not good
 +     *      pratice to have in it's context operations that can take time,
 +     *      hence moving off to a different thread for async processing.
 +     */
      @Override
 -    public void modeChangeNotify(Node node, boolean proactive) {
 -        List<FlowConfig> defaultConfigs = new ArrayList<FlowConfig>();
 -
 -        List<String> puntAction = new ArrayList<String>();
 -        puntAction.add(ActionType.CONTROLLER.toString());
 -
 -        FlowConfig allowARP = new FlowConfig();
 -        allowARP.setInstallInHw(true);
 -        allowARP.setName(FlowConfig.INTERNALSTATICFLOWBEGIN + "Punt ARP" + FlowConfig.INTERNALSTATICFLOWEND);
 -        allowARP.setPriority("1");
 -        allowARP.setNode(node);
 -        allowARP.setEtherType("0x" + Integer.toHexString(EtherTypes.ARP.intValue()).toUpperCase());
 -        allowARP.setActions(puntAction);
 -        defaultConfigs.add(allowARP);
 -
 -        FlowConfig allowLLDP = new FlowConfig();
 -        allowLLDP.setInstallInHw(true);
 -        allowLLDP.setName(FlowConfig.INTERNALSTATICFLOWBEGIN + "Punt LLDP" + FlowConfig.INTERNALSTATICFLOWEND);
 -        allowLLDP.setPriority("1");
 -        allowLLDP.setNode(node);
 -        allowLLDP.setEtherType("0x" + Integer.toHexString(EtherTypes.LLDP.intValue()).toUpperCase());
 -        allowLLDP.setActions(puntAction);
 -        defaultConfigs.add(allowLLDP);
 -
 -        List<String> dropAction = new ArrayList<String>();
 -        dropAction.add(ActionType.DROP.toString());
 -
 -        FlowConfig dropAllConfig = new FlowConfig();
 -        dropAllConfig.setInstallInHw(true);
 -        dropAllConfig.setName(FlowConfig.INTERNALSTATICFLOWBEGIN + "Catch-All Drop" + FlowConfig.INTERNALSTATICFLOWEND);
 -        dropAllConfig.setPriority("0");
 -        dropAllConfig.setNode(node);
 -        dropAllConfig.setActions(dropAction);
 -        defaultConfigs.add(dropAllConfig);
 -
 -        log.info("Forwarding mode for node {} set to {}", node, (proactive ? "proactive" : "reactive"));
 -        for (FlowConfig fc : defaultConfigs) {
 -            Status status = (proactive) ? addStaticFlowInternal(fc, false) : removeStaticFlow(fc);
 -            if (status.isSuccess()) {
 -                log.info("{} Proactive Static flow: {}", (proactive ? "Installed" : "Removed"), fc.getName());
 -            } else {
 -                log.warn("Failed to {} Proactive Static flow: {}", (proactive ? "install" : "remove"), fc.getName());
 +    public void modeChangeNotify(final Node node, final boolean proactive) {
 +        Callable<Status> modeChangeCallable = new Callable<Status>() {
 +            @Override
 +            public Status call() throws Exception {
 +                List<FlowConfig> defaultConfigs = new ArrayList<FlowConfig>();
 +
 +                List<String> puntAction = new ArrayList<String>();
 +                puntAction.add(ActionType.CONTROLLER.toString());
 +
 +                FlowConfig allowARP = new FlowConfig();
 +                allowARP.setInstallInHw(true);
 +                allowARP.setName(FlowConfig.INTERNALSTATICFLOWBEGIN + "Punt ARP" + FlowConfig.INTERNALSTATICFLOWEND);
 +                allowARP.setPriority("1");
 +                allowARP.setNode(node);
 +                allowARP.setEtherType("0x" + Integer.toHexString(EtherTypes.ARP.intValue())
 +                        .toUpperCase());
 +                allowARP.setActions(puntAction);
 +                defaultConfigs.add(allowARP);
 +
 +                FlowConfig allowLLDP = new FlowConfig();
 +                allowLLDP.setInstallInHw(true);
 +                allowLLDP.setName(FlowConfig.INTERNALSTATICFLOWBEGIN + "Punt LLDP" + FlowConfig.INTERNALSTATICFLOWEND);
 +                allowLLDP.setPriority("1");
 +                allowLLDP.setNode(node);
 +                allowLLDP.setEtherType("0x" + Integer.toHexString(EtherTypes.LLDP.intValue())
 +                        .toUpperCase());
 +                allowLLDP.setActions(puntAction);
 +                defaultConfigs.add(allowLLDP);
 +
 +                List<String> dropAction = new ArrayList<String>();
 +                dropAction.add(ActionType.DROP.toString());
 +
 +                FlowConfig dropAllConfig = new FlowConfig();
 +                dropAllConfig.setInstallInHw(true);
 +                dropAllConfig.setName(FlowConfig.INTERNALSTATICFLOWBEGIN + "Catch-All Drop"
 +                        + FlowConfig.INTERNALSTATICFLOWEND);
 +                dropAllConfig.setPriority("0");
 +                dropAllConfig.setNode(node);
 +                dropAllConfig.setActions(dropAction);
 +                defaultConfigs.add(dropAllConfig);
 +
 +                log.info("Forwarding mode for node {} set to {}", node, (proactive ? "proactive" : "reactive"));
 +                for (FlowConfig fc : defaultConfigs) {
 +                    Status status = (proactive) ? addStaticFlowInternal(fc, false) : removeStaticFlow(fc);
 +                    if (status.isSuccess()) {
 +                        log.info("{} Proactive Static flow: {}", (proactive ? "Installed" : "Removed"), fc.getName());
 +                    } else {
 +                        log.warn("Failed to {} Proactive Static flow: {}", (proactive ? "install" : "remove"),
 +                                fc.getName());
 +                    }
 +                }
 +                return new Status(StatusCode.SUCCESS);
              }
 -        }
 +        };
 +
 +        /*
 +         * Execute the work outside the caller context, this could be an
 +         * expensive operation and we don't want to block the caller for it.
 +         */
 +        this.executor.submit(modeChangeCallable);
      }
  
      /**