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=3d6a0292ef67225079b11759a3560bdfddf85377;hp=ccba88614cac2682c89e9d56e8b36ea691fa0da8;hb=9212fed678702583f4a555641208cf1c7b45b829;hpb=39a011908c0ef7a325d6aabf885e1eca98921053 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 ccba88614c..3d6a0292ef 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 @@ -11,8 +11,6 @@ package org.opendaylight.controller.forwardingrulesmanager.internal; import java.io.FileNotFoundException; import java.io.IOException; import java.io.ObjectInputStream; -import java.net.InetAddress; -import java.net.UnknownHostException; import java.util.ArrayList; import java.util.Collections; import java.util.EnumSet; @@ -30,8 +28,6 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.LinkedBlockingQueue; -import org.eclipse.osgi.framework.console.CommandInterpreter; -import org.eclipse.osgi.framework.console.CommandProvider; import org.opendaylight.controller.clustering.services.CacheConfigException; import org.opendaylight.controller.clustering.services.CacheExistException; import org.opendaylight.controller.clustering.services.ICacheUpdateAware; @@ -52,10 +48,7 @@ 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.Controller; -import org.opendaylight.controller.sal.action.Flood; import org.opendaylight.controller.sal.action.Output; -import org.opendaylight.controller.sal.action.PopVlan; import org.opendaylight.controller.sal.connection.ConnectionLocality; import org.opendaylight.controller.sal.core.Config; import org.opendaylight.controller.sal.core.ContainerFlow; @@ -72,11 +65,7 @@ import org.opendaylight.controller.sal.match.Match; import org.opendaylight.controller.sal.match.MatchType; import org.opendaylight.controller.sal.utils.EtherTypes; import org.opendaylight.controller.sal.utils.GlobalConstants; -import org.opendaylight.controller.sal.utils.HexEncode; import org.opendaylight.controller.sal.utils.IObjectReader; -import org.opendaylight.controller.sal.utils.IPProtocols; -import org.opendaylight.controller.sal.utils.NodeConnectorCreator; -import org.opendaylight.controller.sal.utils.NodeCreator; import org.opendaylight.controller.sal.utils.ObjectReader; import org.opendaylight.controller.sal.utils.ObjectWriter; import org.opendaylight.controller.sal.utils.Status; @@ -85,8 +74,6 @@ import org.opendaylight.controller.switchmanager.IInventoryListener; import org.opendaylight.controller.switchmanager.ISwitchManager; import org.opendaylight.controller.switchmanager.ISwitchManagerAware; import org.opendaylight.controller.switchmanager.Subnet; -import org.osgi.framework.BundleContext; -import org.osgi.framework.FrameworkUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -104,13 +91,12 @@ public class ForwardingRulesManager implements IInventoryListener, IObjectReader, ICacheUpdateAware, - CommandProvider, IFlowProgrammerListener { private static final Logger log = LoggerFactory.getLogger(ForwardingRulesManager.class); private static final Logger logsync = LoggerFactory.getLogger("FRMsync"); - private static final String PORTREMOVED = "Port removed"; - private static final String NODEDOWN = "Node is Down"; + private static final String PORT_REMOVED = "Port removed"; + private static final String NODE_DOWN = "Node is Down"; private static final String INVALID_FLOW_ENTRY = "Invalid FlowEntry"; private String frmFileName; private String portGroupFileName; @@ -167,6 +153,8 @@ public class ForwardingRulesManager implements */ static final String WORK_ORDER_CACHE = "frm.workOrder"; static final String WORK_STATUS_CACHE = "frm.workStatus"; + static final String ORIGINAL_SW_VIEW_CACHE = "frm.originalSwView"; + static final String INSTALLED_SW_VIEW_CACHE = "frm.installedSwView"; /* * Data structure responsible for distributing the FlowEntryInstall requests @@ -269,12 +257,36 @@ public class ForwardingRulesManager implements private Status addEntry(FlowEntry flowEntry, boolean async) { // Sanity Check - if (flowEntry == null || flowEntry.getNode() == null) { + if (flowEntry == null || flowEntry.getNode() == null || flowEntry.getFlow() == null) { String logMsg = INVALID_FLOW_ENTRY + ": {}"; log.warn(logMsg, flowEntry); return new Status(StatusCode.NOTACCEPTABLE, INVALID_FLOW_ENTRY); } + /* + * Redundant Check: Check if the request is a redundant one from the + * same application the flowEntry is equal to an existing one. Given we + * do not have an application signature in the requested FlowEntry yet, + * we are here detecting the above condition by comparing the flow + * names, if set. If they are equal to the installed flow, most likely + * this is a redundant installation request from the same application + * and we can silently return success + * + * TODO: in future a sort of application reference list mechanism will + * be added to the FlowEntry so that exact flow can be used by different + * applications. + */ + FlowEntry present = this.originalSwView.get(flowEntry); + if (present != null) { + boolean sameFlow = present.getFlow().equals(flowEntry.getFlow()); + boolean sameApp = present.getFlowName() != null && present.getFlowName().equals(flowEntry.getFlowName()); + if (sameFlow && sameApp) { + log.trace("Skipping redundant request for flow {} on node {}", flowEntry.getFlowName(), + flowEntry.getNode()); + return new Status(StatusCode.SUCCESS, "Entry is already present"); + } + } + /* * Derive the container flow merged entries to install In presence of N * container flows, we may end up with N different entries to install... @@ -387,7 +399,7 @@ public class ForwardingRulesManager implements // Sanity checks if (currentFlowEntry == null || currentFlowEntry.getNode() == null || newFlowEntry == null - || newFlowEntry.getNode() == null) { + || newFlowEntry.getNode() == null || newFlowEntry.getFlow() == null) { String msg = "Modify: " + INVALID_FLOW_ENTRY; String logMsg = msg + ": {} or {}"; log.warn(logMsg, currentFlowEntry, newFlowEntry); @@ -586,8 +598,8 @@ public class ForwardingRulesManager implements // Update DB newEntries.setRequestId(status.getRequestId()); - updateLocalDatabase(currentEntries, false); - updateLocalDatabase(newEntries, true); + updateSwViews(currentEntries, false); + updateSwViews(newEntries, true); return status; } @@ -608,7 +620,7 @@ public class ForwardingRulesManager implements Status error = new Status(null, null); // Sanity Check - if (flowEntry == null || flowEntry.getNode() == null) { + if (flowEntry == null || flowEntry.getNode() == null || flowEntry.getFlow() == null) { String logMsg = INVALID_FLOW_ENTRY + ": {}"; log.warn(logMsg, flowEntry); return new Status(StatusCode.NOTACCEPTABLE, INVALID_FLOW_ENTRY); @@ -701,7 +713,7 @@ public class ForwardingRulesManager implements log.trace("Removed {}", entry.getInstall()); // Update DB - updateLocalDatabase(entry, false); + updateSwViews(entry, false); return status; } @@ -753,7 +765,7 @@ public class ForwardingRulesManager implements // Update DB entry.setRequestId(status.getRequestId()); - updateLocalDatabase(entry, true); + updateSwViews(entry, true); return status; } @@ -798,10 +810,7 @@ public class ForwardingRulesManager implements return null; } - private void updateLocalDatabase(FlowEntryInstall entry, boolean add) { - // Update the software view - updateSwViewes(entry, add); - + private void updateIndexDatabase(FlowEntryInstall entry, boolean add) { // Update node indexed flow database updateNodeFlowsDB(entry, add); @@ -812,7 +821,7 @@ public class ForwardingRulesManager implements /* * Update the node mapped flows database */ - private void updateSwViewes(FlowEntryInstall flowEntries, boolean add) { + private void updateSwViews(FlowEntryInstall flowEntries, boolean add) { if (add) { originalSwView.put(flowEntries.getOriginal(), flowEntries.getOriginal()); installedSwView.put(flowEntries, flowEntries); @@ -838,6 +847,17 @@ public class ForwardingRulesManager implements } if (add) { + // there may be an already existing entry. + // remove it before adding the new one. + // This is necessary since we have observed that in some cases + // Infinispan does aggregation for operations (eg:- remove and then put a different value) + // related to the same key within the same transaction. + // Need this defensive code as the new FlowEntryInstall may be different + // than the old one even though the equals method returns true. This is because + // the equals method does not take into account the action list. + if(nodeIndeces.contains(flowEntries)) { + nodeIndeces.remove(flowEntries); + } nodeIndeces.add(flowEntries); } else { nodeIndeces.remove(flowEntries); @@ -872,6 +892,11 @@ public class ForwardingRulesManager implements } if (add) { + // same comments in the similar code section in + // updateNodeFlowsDB method apply here too + if(indices.contains(flowEntries)) { + indices.remove(flowEntries); + } indices.add(flowEntries); } else { indices.remove(flowEntries); @@ -911,7 +936,7 @@ public class ForwardingRulesManager implements // Update DB if (status.isSuccess()) { - updateLocalDatabase(target, false); + updateSwViews(target, false); } else { // log the error log.trace("SDN Plugin failed to remove the flow: {}. The failure is: {}", target.getInstall(), @@ -1154,8 +1179,6 @@ public class ForwardingRulesManager implements private void nonClusterObjectCreate() { originalSwView = new ConcurrentHashMap(); installedSwView = new ConcurrentHashMap(); - nodeFlows = new ConcurrentHashMap>(); - groupFlows = new ConcurrentHashMap>(); TSPolicies = new ConcurrentHashMap(); staticFlowsOrdinal = new ConcurrentHashMap(); portGroupConfigs = new ConcurrentHashMap(); @@ -1164,11 +1187,6 @@ public class ForwardingRulesManager implements inactiveFlows = new ConcurrentHashMap(); } - private void registerWithOSGIConsole() { - BundleContext bundleContext = FrameworkUtil.getBundle(this.getClass()).getBundleContext(); - bundleContext.registerService(CommandProvider.class.getName(), this, null); - } - @Override public void setTSPolicyData(String policyname, Object o, boolean add) { @@ -1213,7 +1231,7 @@ public class ForwardingRulesManager implements if (policyName != null && !policyName.trim().isEmpty()) { for (Map.Entry entry : this.originalSwView.entrySet()) { if (policyName.equals(entry.getKey().getGroupName())) { - list.add(entry.getKey().clone()); + list.add(entry.getValue().clone()); } } } @@ -1226,7 +1244,7 @@ public class ForwardingRulesManager implements if (policyName != null && !policyName.trim().isEmpty()) { for (Map.Entry entry : this.installedSwView.entrySet()) { if (policyName.equals(entry.getKey().getGroupName())) { - list.add(entry.getKey().getInstall().clone()); + list.add(entry.getValue().getInstall().clone()); } } } @@ -1354,21 +1372,15 @@ public class ForwardingRulesManager implements log.debug("Allocating caches for Container {}", container.getName()); try { - clusterContainerService.createCache("frm.originalSwView", + clusterContainerService.createCache(ORIGINAL_SW_VIEW_CACHE, EnumSet.of(IClusterServices.cacheMode.TRANSACTIONAL)); - clusterContainerService.createCache("frm.installedSwView", + clusterContainerService.createCache(INSTALLED_SW_VIEW_CACHE, EnumSet.of(IClusterServices.cacheMode.TRANSACTIONAL)); clusterContainerService.createCache("frm.inactiveFlows", EnumSet.of(IClusterServices.cacheMode.TRANSACTIONAL)); - clusterContainerService.createCache("frm.nodeFlows", - EnumSet.of(IClusterServices.cacheMode.TRANSACTIONAL)); - - clusterContainerService.createCache("frm.groupFlows", - EnumSet.of(IClusterServices.cacheMode.TRANSACTIONAL)); - clusterContainerService.createCache("frm.staticFlows", EnumSet.of(IClusterServices.cacheMode.TRANSACTIONAL)); @@ -1409,14 +1421,14 @@ public class ForwardingRulesManager implements log.debug("Retrieving Caches for Container {}", container.getName()); - map = clusterContainerService.getCache("frm.originalSwView"); + map = clusterContainerService.getCache(ORIGINAL_SW_VIEW_CACHE); if (map != null) { originalSwView = (ConcurrentMap) map; } else { log.error("Retrieval of frm.originalSwView cache failed for Container {}", container.getName()); } - map = clusterContainerService.getCache("frm.installedSwView"); + map = clusterContainerService.getCache(INSTALLED_SW_VIEW_CACHE); if (map != null) { installedSwView = (ConcurrentMap) map; } else { @@ -1430,20 +1442,6 @@ public class ForwardingRulesManager implements log.error("Retrieval of frm.inactiveFlows cache failed for Container {}", container.getName()); } - map = clusterContainerService.getCache("frm.nodeFlows"); - if (map != null) { - nodeFlows = (ConcurrentMap>) map; - } else { - log.error("Retrieval of cache failed for Container {}", container.getName()); - } - - map = clusterContainerService.getCache("frm.groupFlows"); - if (map != null) { - groupFlows = (ConcurrentMap>) map; - } else { - log.error("Retrieval of frm.groupFlows cache failed for Container {}", container.getName()); - } - map = clusterContainerService.getCache("frm.staticFlows"); if (map != null) { staticFlows = (ConcurrentMap) map; @@ -1641,7 +1639,7 @@ public class ForwardingRulesManager implements // Take note of this controller generated static flow toRemove.add(entry.getKey()); } else { - config.setStatus(NODEDOWN); + config.setStatus(NODE_DOWN); } } } @@ -2066,26 +2064,6 @@ public class ForwardingRulesManager implements public void subnetNotify(Subnet sub, boolean add) { } - private void installImplicitARPReplyPunt(Node node) { - - if (node == null) { - return; - } - - List puntAction = new ArrayList(); - puntAction.add(ActionType.CONTROLLER.toString()); - - FlowConfig allowARP = new FlowConfig(); - allowARP.setInstallInHw(true); - allowARP.setName(FlowConfig.INTERNALSTATICFLOWBEGIN + "Punt ARP Reply" + FlowConfig.INTERNALSTATICFLOWEND); - allowARP.setPriority("500"); - allowARP.setNode(node); - allowARP.setEtherType("0x" + Integer.toHexString(EtherTypes.ARP.intValue()).toUpperCase()); - allowARP.setDstMac(HexEncode.bytesToHexString(switchManager.getControllerMAC())); - allowARP.setActions(puntAction); - addStaticFlowInternal(allowARP, true); // skip validation on internal static flow name - } - /** * (non-Javadoc) * @@ -2172,7 +2150,7 @@ public class ForwardingRulesManager implements List toRemove = new ArrayList(nodeFlows.get(node)); for (FlowEntryInstall entry : toRemove) { - updateLocalDatabase(entry, false); + updateSwViews(entry, false); } } } @@ -2296,7 +2274,7 @@ public class ForwardingRulesManager implements if (fei.getGroupName().equals(FlowConfig.STATICFLOWGROUP)) { FlowConfig flowConfig = getStaticFlow(fei.getFlowName(), fei.getNode()); if (flowConfig != null) { - flowConfig.setStatus(PORTREMOVED); + flowConfig.setStatus(PORT_REMOVED); updated = true; } } @@ -2410,17 +2388,6 @@ public class ForwardingRulesManager implements return true; } - private void usePortGroupConfig(String name) { - PortGroupConfig config = portGroupConfigs.get(name); - if (config == null) { - return; - } - if (portGroupProvider != null) { - Map data = portGroupProvider.getPortGroupData(config); - portGroupData.put(config, data); - } - } - @Override public Map getPortGroupConfigs() { return portGroupConfigs; @@ -2502,9 +2469,10 @@ public class ForwardingRulesManager implements portGroupProvider.registerPortGroupChange(this); } - cacheStartup(); + nodeFlows = new ConcurrentHashMap>(); + groupFlows = new ConcurrentHashMap>(); - registerWithOSGIConsole(); + cacheStartup(); /* * If we are not the first cluster node to come up, do not initialize @@ -2603,9 +2571,11 @@ public class ForwardingRulesManager implements * flow merging is not an injective function */ updateFlowsContainerFlow(); + } else if (event instanceof UpdateIndexDBs) { + UpdateIndexDBs update = (UpdateIndexDBs)event; + updateIndexDatabase(update.getFei(), update.isAddition()); } else { - log.warn("Dequeued unknown event {}", event.getClass() - .getSimpleName()); + log.warn("Dequeued unknown event {}", event.getClass().getSimpleName()); } } catch (InterruptedException e) { // clear pending events @@ -2654,6 +2624,12 @@ public class ForwardingRulesManager implements // Start event handler thread frmEventHandler.start(); + // replay the installedSwView data structure to populate + // node flows and group flows + for (FlowEntryInstall fei : installedSwView.values()) { + pendingEvents.offer(new UpdateIndexDBs(fei, true)); + } + /* * Read startup and build database if we have not already gotten the * configurations synced from another node @@ -2892,125 +2868,36 @@ public class ForwardingRulesManager implements } } - /* - * OSGI COMMANDS - */ - @Override - public String getHelp() { - StringBuffer help = new StringBuffer(); - help.append("---FRM Matrix Application---\n"); - help.append("\t printMatrixData - Prints the Matrix Configs\n"); - help.append("\t addMatrixConfig \n"); - help.append("\t delMatrixConfig \n"); - help.append("\t useMatrixConfig \n"); - return help.toString(); - } - - public void _printMatrixData(CommandInterpreter ci) { - ci.println("Configs : "); - ci.println("---------"); - ci.println(portGroupConfigs); - - ci.println("Data : "); - ci.println("------"); - ci.println(portGroupData); - } - - public void _addMatrixConfig(CommandInterpreter ci) { - String name = ci.nextArgument(); - String regex = ci.nextArgument(); - addPortGroupConfig(name, regex, false); - } - - public void _delMatrixConfig(CommandInterpreter ci) { - String name = ci.nextArgument(); - delPortGroupConfig(name); - } + private class UpdateIndexDBs extends FRMEvent { + private FlowEntryInstall fei; + private boolean add; - public void _useMatrixConfig(CommandInterpreter ci) { - String name = ci.nextArgument(); - usePortGroupConfig(name); - } - - public void _arpPunt(CommandInterpreter ci) { - String switchId = ci.nextArgument(); - long swid = HexEncode.stringToLong(switchId); - Node node = NodeCreator.createOFNode(swid); - installImplicitARPReplyPunt(node); - } - - public void _frmaddflow(CommandInterpreter ci) throws UnknownHostException { - Node node = null; - String nodeId = ci.nextArgument(); - if (nodeId == null) { - ci.print("Node id not specified"); - return; - } - try { - node = NodeCreator.createOFNode(Long.valueOf(nodeId)); - } catch (NumberFormatException e) { - ci.print("Node id not a number"); - return; + /** + * + * @param fei the flow entry which was installed/removed on the netwrok node + * @param update + */ + UpdateIndexDBs(FlowEntryInstall fei, boolean add) { + this.fei = fei; + this.add = add; } - ci.println(this.programmer.addFlow(node, getSampleFlow(node))); - } - public void _frmremoveflow(CommandInterpreter ci) throws UnknownHostException { - Node node = null; - String nodeId = ci.nextArgument(); - if (nodeId == null) { - ci.print("Node id not specified"); - return; - } - try { - node = NodeCreator.createOFNode(Long.valueOf(nodeId)); - } catch (NumberFormatException e) { - ci.print("Node id not a number"); - return; + + /** + * @return the flowEntryInstall object which was added/removed + * to/from the installed software view cache + */ + public FlowEntryInstall getFei() { + return fei; } - ci.println(this.programmer.removeFlow(node, getSampleFlow(node))); - } - - private Flow getSampleFlow(Node node) throws UnknownHostException { - NodeConnector port = NodeConnectorCreator.createOFNodeConnector((short) 24, node); - NodeConnector oport = NodeConnectorCreator.createOFNodeConnector((short) 30, node); - byte srcMac[] = { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78, (byte) 0x9a, (byte) 0xbc }; - byte dstMac[] = { (byte) 0x1a, (byte) 0x2b, (byte) 0x3c, (byte) 0x4d, (byte) 0x5e, (byte) 0x6f }; - InetAddress srcIP = InetAddress.getByName("172.28.30.50"); - InetAddress dstIP = InetAddress.getByName("171.71.9.52"); - InetAddress ipMask = InetAddress.getByName("255.255.255.0"); - InetAddress ipMask2 = InetAddress.getByName("255.0.0.0"); - short ethertype = EtherTypes.IPv4.shortValue(); - short vlan = (short) 27; - byte vlanPr = 3; - Byte tos = 4; - byte proto = IPProtocols.TCP.byteValue(); - short src = (short) 55000; - short dst = 80; - /* - * Create a SAL Flow aFlow + /** + * + * @return whether this was an flow addition or removal */ - Match match = new Match(); - match.setField(MatchType.IN_PORT, port); - match.setField(MatchType.DL_SRC, srcMac); - match.setField(MatchType.DL_DST, dstMac); - match.setField(MatchType.DL_TYPE, ethertype); - match.setField(MatchType.DL_VLAN, vlan); - match.setField(MatchType.DL_VLAN_PR, vlanPr); - match.setField(MatchType.NW_SRC, srcIP, ipMask); - match.setField(MatchType.NW_DST, dstIP, ipMask2); - match.setField(MatchType.NW_TOS, tos); - match.setField(MatchType.NW_PROTO, proto); - match.setField(MatchType.TP_SRC, src); - match.setField(MatchType.TP_DST, dst); - - List actions = new ArrayList(); - actions.add(new Output(oport)); - actions.add(new PopVlan()); - actions.add(new Flood()); - actions.add(new Controller()); - return new Flow(match, actions); + public boolean isAddition() { + return add; + } } @Override @@ -3018,88 +2905,6 @@ public class ForwardingRulesManager implements return saveConfig(); } - public void _frmNodeFlows(CommandInterpreter ci) { - String nodeId = ci.nextArgument(); - Node node = Node.fromString(nodeId); - if (node == null) { - ci.println("frmNodeFlows [verbose]"); - return; - } - boolean verbose = false; - String verboseCheck = ci.nextArgument(); - if (verboseCheck != null) { - verbose = verboseCheck.equals("true"); - } - - if (!nodeFlows.containsKey(node)) { - return; - } - // Dump per node database - for (FlowEntryInstall entry : nodeFlows.get(node)) { - if (!verbose) { - ci.println(node + " " + installedSwView.get(entry).getFlowName()); - } else { - ci.println(node + " " + installedSwView.get(entry).toString()); - } - } - } - - public void _frmGroupFlows(CommandInterpreter ci) { - String group = ci.nextArgument(); - if (group == null) { - ci.println("frmGroupFlows [verbose]"); - return; - } - boolean verbose = false; - String verboseCheck = ci.nextArgument(); - if (verboseCheck != null) { - verbose = verboseCheck.equalsIgnoreCase("true"); - } - - if (!groupFlows.containsKey(group)) { - return; - } - // Dump per node database - ci.println("Group " + group + ":\n"); - for (FlowEntryInstall flowEntry : groupFlows.get(group)) { - if (!verbose) { - ci.println(flowEntry.getNode() + " " + flowEntry.getFlowName()); - } else { - ci.println(flowEntry.getNode() + " " + flowEntry.toString()); - } - } - } - - public void _frmProcessErrorEvent(CommandInterpreter ci) throws UnknownHostException { - Node node = null; - long reqId = 0L; - String nodeId = ci.nextArgument(); - if (nodeId == null) { - ci.print("Node id not specified"); - return; - } - String requestId = ci.nextArgument(); - if (requestId == null) { - ci.print("Request id not specified"); - return; - } - try { - node = NodeCreator.createOFNode(Long.valueOf(nodeId)); - } catch (NumberFormatException e) { - ci.print("Node id not a number"); - return; - } - try { - reqId = Long.parseLong(requestId); - } catch (NumberFormatException e) { - ci.print("Request id not a number"); - return; - } - // null for error object is good enough for now - ErrorReportedEvent event = new ErrorReportedEvent(reqId, node, null); - this.processErrorEvent(event); - } - @Override public void flowRemoved(Node node, Flow flow) { log.trace("Received flow removed notification on {} for {}", node, flow); @@ -3125,13 +2930,21 @@ public class ForwardingRulesManager implements } if (target != null) { // Update Configuration database - target.toggleInstallation(); - target.setStatus(StatusCode.SUCCESS.toString()); + if (target.getHardTimeout() != null || target.getIdleTimeout() != null) { + /* + * No need for checking if actual values: these strings were + * validated at configuration creation. Also, after a switch + * down scenario, no use to reinstall a timed flow. Mark it as + * "do not install". User can manually toggle it. + */ + target.toggleInstallation(); + } + target.setStatus(StatusCode.GONE.toString()); staticFlows.put(key, target); } // Update software views - this.updateLocalDatabase(installedEntry, false); + this.updateSwViews(installedEntry, false); } @Override @@ -3168,7 +2981,7 @@ public class ForwardingRulesManager implements } if (target != null) { // This was a flow install, update database - this.updateLocalDatabase(target, false); + this.updateSwViews(target, false); // also update the config if(FlowConfig.STATICFLOWGROUP.equals(target.getGroupName())) { ConcurrentMap.Entry staticFlowEntry = getStaticFlowEntry(target.getFlowName(),target.getNode()); @@ -3238,6 +3051,13 @@ public class ForwardingRulesManager implements @Override public void entryUpdated(Object key, Object new_value, String cacheName, boolean originLocal) { + /* + * Streamline the updates for the per node and per group index databases + */ + if (cacheName.equals(INSTALLED_SW_VIEW_CACHE)) { + pendingEvents.offer(new UpdateIndexDBs((FlowEntryInstall)new_value, true)); + } + if (originLocal) { /* * Local updates are of no interest @@ -3289,7 +3109,43 @@ public class ForwardingRulesManager implements @Override public void entryDeleted(Object key, String cacheName, boolean originLocal) { /* - * Do nothing + * Streamline the updates for the per node and per group index databases */ + if (cacheName.equals(INSTALLED_SW_VIEW_CACHE)) { + pendingEvents.offer(new UpdateIndexDBs((FlowEntryInstall)key, false)); + } + } + + /** + * {@inheritDoc} + */ + @Override + public List getFlowEntriesForNode(Node node) { + List list = new ArrayList(); + if (node != null) { + for (Map.Entry entry : this.originalSwView.entrySet()) { + if (node.equals(entry.getKey().getNode())) { + list.add(entry.getValue().clone()); + } + } + } + return list; + } + + /** + * {@inheritDoc} + */ + @Override + public List getInstalledFlowEntriesForNode(Node node) { + List list = new ArrayList(); + if (node != null) { + List flowEntryInstallList = this.nodeFlows.get(node); + if(flowEntryInstallList != null) { + for(FlowEntryInstall fi: flowEntryInstallList) { + list.add(fi.getInstall().clone()); + } + } + } + return list; } }