X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fforwardingrulesmanager%2Fimplementation%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fforwardingrulesmanager%2Finternal%2FForwardingRulesManager.java;h=46008b24c638241c665a7bde863f0ff5052d587a;hp=bce7dd30ba59de6c9707062f3fdeaf9f23a8141d;hb=66249d6ccc367fad055a269f561860d2d96af385;hpb=633fd9012d8ff920283da437131b19d8cd3c2330 diff --git a/opendaylight/forwardingrulesmanager/implementation/src/main/java/org/opendaylight/controller/forwardingrulesmanager/internal/ForwardingRulesManager.java b/opendaylight/forwardingrulesmanager/implementation/src/main/java/org/opendaylight/controller/forwardingrulesmanager/internal/ForwardingRulesManager.java index bce7dd30ba..46008b24c6 100644 --- a/opendaylight/forwardingrulesmanager/implementation/src/main/java/org/opendaylight/controller/forwardingrulesmanager/internal/ForwardingRulesManager.java +++ b/opendaylight/forwardingrulesmanager/implementation/src/main/java/org/opendaylight/controller/forwardingrulesmanager/internal/ForwardingRulesManager.java @@ -50,6 +50,9 @@ import org.opendaylight.controller.forwardingrulesmanager.PortGroupProvider; import org.opendaylight.controller.forwardingrulesmanager.implementation.data.FlowEntryDistributionOrder; import org.opendaylight.controller.sal.action.Action; import org.opendaylight.controller.sal.action.ActionType; +import org.opendaylight.controller.sal.action.Enqueue; +import org.opendaylight.controller.sal.action.Flood; +import org.opendaylight.controller.sal.action.FloodAll; import org.opendaylight.controller.sal.action.Output; import org.opendaylight.controller.sal.connection.ConnectionLocality; import org.opendaylight.controller.sal.core.Config; @@ -243,6 +246,57 @@ public class ForwardingRulesManager implements return null; } + /** + * Checks if the FlowEntry targets are valid for this container + * + * @param flowEntry + * The flow entry to test + * @return a Status object representing the result of the validation + */ + private Status validateEntry(FlowEntry flowEntry) { + // Node presence check + Node node = flowEntry.getNode(); + if (!switchManager.getNodes().contains(node)) { + return new Status(StatusCode.BADREQUEST, String.format("Node %s is not present in this container", node)); + } + + // Ports and actions validation check + Flow flow = flowEntry.getFlow(); + Match match = flow.getMatch(); + if (match.isPresent(MatchType.IN_PORT)) { + NodeConnector inputPort = (NodeConnector)match.getField(MatchType.IN_PORT).getValue(); + if (!switchManager.getNodeConnectors(node).contains(inputPort)) { + String msg = String.format("Ingress port %s is not present on this container", inputPort); + return new Status(StatusCode.BADREQUEST, msg); + } + } + for (Action action : flow.getActions()) { + if (action instanceof Flood && !GlobalConstants.DEFAULT.toString().equals(getContainerName())) { + return new Status(StatusCode.BADREQUEST, String.format("Flood is only allowed in default container")); + } + if (action instanceof FloodAll && !GlobalConstants.DEFAULT.toString().equals(getContainerName())) { + return new Status(StatusCode.BADREQUEST, String.format("FloodAll is only allowed in default container")); + } + if (action instanceof Output) { + Output out = (Output)action; + NodeConnector outputPort = out.getPort(); + if (!switchManager.getNodeConnectors(node).contains(outputPort)) { + String msg = String.format("Output port %s is not present on this container", outputPort); + return new Status(StatusCode.BADREQUEST, msg); + } + } + if (action instanceof Enqueue) { + Enqueue out = (Enqueue)action; + NodeConnector outputPort = out.getPort(); + if (!switchManager.getNodeConnectors(node).contains(outputPort)) { + String msg = String.format("Enqueue port %s is not present on this container", outputPort); + return new Status(StatusCode.BADREQUEST, msg); + } + } + } + return new Status(StatusCode.SUCCESS); + } + /** * Adds a flow entry onto the network node It runs various validity checks * and derive the final container flows merged entries that will be @@ -264,6 +318,15 @@ public class ForwardingRulesManager implements return new Status(StatusCode.NOTACCEPTABLE, INVALID_FLOW_ENTRY); } + // Operational check: input, output and queue ports presence check and + // action validation for this container + Status status = validateEntry(flowEntry); + if (!status.isSuccess()) { + String msg = String.format("%s: %s", INVALID_FLOW_ENTRY, status.getDescription()); + log.warn("{}: {}", msg, flowEntry); + return new Status(StatusCode.NOTACCEPTABLE, msg); + } + /* * Redundant Check: Check if the request is a redundant one from the * same application the flowEntry is equal to an existing one. Given we @@ -331,7 +394,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; @@ -422,6 +485,15 @@ public class ForwardingRulesManager implements return new Status(StatusCode.SUCCESS, msg); } + // Operational check: input, output and queue ports presence check and + // action validation for this container + Status status = validateEntry(newFlowEntry); + if (!status.isSuccess()) { + String msg = String.format("Modify: %s: %s", INVALID_FLOW_ENTRY, status.getDescription()); + log.warn("{}: {}", msg, newFlowEntry); + return new Status(StatusCode.NOTACCEPTABLE, msg); + } + /* * Conflict Check: Verify the new entry would not conflict with an * existing one. This is a loose check on the previous original flow @@ -494,7 +566,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 +626,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 +638,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 +654,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 +747,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 +758,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 +772,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 +804,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 +814,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 +829,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()); } /** @@ -1111,7 +1193,10 @@ public class ForwardingRulesManager implements List list = new ArrayList(groupFlows.get(groupName)); toBeRemoved = list.size(); for (FlowEntryInstall entry : list) { - Status status = this.removeEntry(entry.getOriginal(), false); + // since this is the entry that was stored in groupFlows + // it is already validated and merged + // so can call removeEntryInternal directly + Status status = this.removeEntryInternal(entry, false); if (status.isSuccess()) { toBeRemoved -= 1; } else { @@ -1505,15 +1590,25 @@ public class ForwardingRulesManager implements @Override public Status addStaticFlow(FlowConfig config) { + return addStaticFlow(config, false); + } + + private Status addStaticFlow(FlowConfig config, boolean async) { // Configuration object validation - Status status = config.validate(container); + Status status = config.validate(); if (!status.isSuccess()) { log.warn("Invalid Configuration for flow {}. The failure is {}", config, status.getDescription()); String error = "Invalid Configuration (" + status.getDescription() + ")"; config.setStatus(error); return new Status(StatusCode.BADREQUEST, error); } - return addStaticFlowInternal(config, false); + return addStaticFlowInternal(config, async, false); + } + + + @Override + public Status addStaticFlowAsync(FlowConfig config) { + return addStaticFlow(config, true); } /** @@ -1531,7 +1626,7 @@ public class ForwardingRulesManager implements * installation on the network node was successful * @return The status of this request */ - private Status addStaticFlowInternal(FlowConfig config, boolean restore) { + private Status addStaticFlowInternal(FlowConfig config, boolean async, boolean restore) { boolean multipleFlowPush = false; String error; Status status; @@ -1568,7 +1663,7 @@ public class ForwardingRulesManager implements // Program hw if (config.installInHw()) { FlowEntry entry = config.getFlowEntry(); - status = this.installFlowEntry(entry); + status = async ? this.installFlowEntryAsync(entry) : this.installFlowEntry(entry); if (!status.isSuccess()) { config.setStatus(status.getDescription()); if (!restore) { @@ -1670,6 +1765,7 @@ public class ForwardingRulesManager implements config.setStatus(StatusCode.SUCCESS.toString()); break; default: + break; } } } @@ -1679,6 +1775,15 @@ public class ForwardingRulesManager implements @Override public Status removeStaticFlow(FlowConfig config) { + return removeStaticFlow(config, false); + } + + @Override + public Status removeStaticFlowAsync(FlowConfig config) { + return removeStaticFlow(config, true); + } + + private Status removeStaticFlow(FlowConfig config, boolean async) { /* * No config.isInternal() check as NB does not take this path and GUI * cannot issue a delete on an internal generated flow. We need this @@ -1702,7 +1807,8 @@ public class ForwardingRulesManager implements } // Program the network node - Status status = this.uninstallFlowEntry(config.getFlowEntry()); + Status status = async ? this.uninstallFlowEntryAsync(config.getFlowEntry()) : this.uninstallFlowEntry(config + .getFlowEntry()); // Update configuration database if programming was successful if (status.isSuccess()) { @@ -1714,6 +1820,15 @@ public class ForwardingRulesManager implements @Override public Status removeStaticFlow(String name, Node node) { + return removeStaticFlow(name, node, false); + } + + @Override + public Status removeStaticFlowAsync(String name, Node node) { + return removeStaticFlow(name, node, true); + } + + private Status removeStaticFlow(String name, Node node, boolean async) { // Look for the target configuration entry Integer key = 0; FlowConfig target = null; @@ -1744,7 +1859,7 @@ public class ForwardingRulesManager implements } // Program the network node - Status status = this.removeEntry(target.getFlowEntry(), false); + Status status = this.removeEntry(target.getFlowEntry(), async); // Update configuration database if programming was successful if (status.isSuccess()) { @@ -1765,7 +1880,7 @@ public class ForwardingRulesManager implements } // Validity Check - Status status = newFlowConfig.validate(container); + Status status = newFlowConfig.validate(); if (!status.isSuccess()) { String msg = "Invalid Configuration (" + status.getDescription() + ")"; newFlowConfig.setStatus(msg); @@ -1845,7 +1960,7 @@ public class ForwardingRulesManager implements } } if (target != null) { - Status status = target.validate(container); + Status status = target.validate(); if (!status.isSuccess()) { log.warn(status.getDescription()); return status; @@ -1995,7 +2110,7 @@ public class ForwardingRulesManager implements } for (ConfigurationObject conf : configurationService.retrieveConfiguration(this, STATIC_FLOWS_FILE_NAME)) { - addStaticFlowInternal((FlowConfig) conf, true); + addStaticFlowInternal((FlowConfig) conf, false, true); } } @@ -2107,7 +2222,7 @@ public class ForwardingRulesManager implements // check if the frm really needs to act on the notification. // this is to check against duplicate notifications if(programInternalFlow(proactive, fc)) { - Status status = (proactive) ? addStaticFlowInternal(fc, false) : removeStaticFlow(fc); + Status status = (proactive) ? addStaticFlowInternal(fc, false, false) : removeStaticFlow(fc); if (status.isSuccess()) { log.trace("{} Proactive Static flow: {}", (proactive ? "Installed" : "Removed"), fc.getName()); } else { @@ -2227,7 +2342,7 @@ public class ForwardingRulesManager implements for (FlowConfig flowConfig : flowConfigForNode) { if (doesFlowContainNodeConnector(flowConfig.getFlow(), nodeConnector)) { if (flowConfig.installInHw() && !flowConfig.getStatus().equals(StatusCode.SUCCESS.toString())) { - Status status = this.installFlowEntry(flowConfig.getFlowEntry()); + Status status = this.installFlowEntryAsync(flowConfig.getFlowEntry()); if (!status.isSuccess()) { flowConfig.setStatus(status.getDescription()); } else { @@ -2290,7 +2405,7 @@ public class ForwardingRulesManager implements if ((staticFlow.getNode().equals(node)) && (staticFlow.getPortGroup().equals(config.getName()))) { for (Short port : data.getPorts()) { FlowConfig derivedFlow = getDerivedFlowConfig(staticFlow, config.getName(), port); - addStaticFlowInternal(derivedFlow, false); + addStaticFlowInternal(derivedFlow, false, false); } } } @@ -2526,13 +2641,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 @@ -2747,6 +2862,7 @@ public class ForwardingRulesManager implements this.reinstallAllFlowEntries(); break; default: + break; } // Update our configuration DB @@ -3153,4 +3269,5 @@ public class ForwardingRulesManager implements } return list; } + }