X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fswitchmanager%2Fimplementation%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fswitchmanager%2Finternal%2FSwitchManager.java;h=07252b06f78dfb2a80a4c88d112f6b3f41fd5422;hp=19f45e63c591dbde396e0929141c5c042a55adf5;hb=7e696f1ff645d647e75bb34723b32d6c4b665f95;hpb=619f87d7ff5b11898aa1571d5fad7c9468753ecd diff --git a/opendaylight/switchmanager/implementation/src/main/java/org/opendaylight/controller/switchmanager/internal/SwitchManager.java b/opendaylight/switchmanager/implementation/src/main/java/org/opendaylight/controller/switchmanager/internal/SwitchManager.java index 19f45e63c5..07252b06f7 100644 --- a/opendaylight/switchmanager/implementation/src/main/java/org/opendaylight/controller/switchmanager/internal/SwitchManager.java +++ b/opendaylight/switchmanager/implementation/src/main/java/org/opendaylight/controller/switchmanager/internal/SwitchManager.java @@ -12,13 +12,10 @@ import java.io.FileNotFoundException; import java.io.IOException; import java.io.ObjectInputStream; import java.net.InetAddress; -import java.net.NetworkInterface; -import java.net.SocketException; import java.util.ArrayList; import java.util.Collections; import java.util.Dictionary; import java.util.EnumSet; -import java.util.Enumeration; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -56,7 +53,6 @@ import org.opendaylight.controller.sal.inventory.IInventoryService; import org.opendaylight.controller.sal.inventory.IListenInventoryUpdates; import org.opendaylight.controller.sal.reader.NodeDescription; 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.Status; import org.opendaylight.controller.sal.utils.StatusCode; @@ -102,6 +98,7 @@ public class SwitchManager implements ISwitchManager, IConfigurationContainerAwa private ConcurrentMap controllerProps; private IInventoryService inventoryService; private IStatisticsManager statisticsManager; + private IControllerProperties controllerProperties; private IConfigurationContainerService configurationService; private final Set switchManagerAware = Collections .synchronizedSet(new HashSet()); @@ -171,13 +168,13 @@ public class SwitchManager implements ISwitchManager, IConfigurationContainerAwa retrieveCaches(); // Add controller MAC, if first node in the cluster - if (!controllerProps.containsKey(MacAddress.name)) { - byte controllerMac[] = getHardwareMAC(); + if ((!controllerProps.containsKey(MacAddress.name)) && (controllerProperties != null)) { + Property controllerMac = controllerProperties.getControllerProperty(MacAddress.name); if (controllerMac != null) { - Property existing = controllerProps.putIfAbsent(MacAddress.name, new MacAddress(controllerMac)); + Property existing = controllerProps.putIfAbsent(MacAddress.name, controllerMac); if (existing == null && log.isTraceEnabled()) { log.trace("Container {}: Setting controller MAC address in the cluster: {}", getContainerName(), - HexEncode.bytesToHexStringFormat(controllerMac)); + controllerMac); } } } @@ -1004,7 +1001,8 @@ public class SwitchManager implements ISwitchManager, IConfigurationContainerAwa } } - boolean proactiveForwarding = false; + boolean forwardingModeChanged = false; + // copy node properties from config if (nodeConfigList != null) { String nodeId = node.toString(); @@ -1014,7 +1012,7 @@ public class SwitchManager implements ISwitchManager, IConfigurationContainerAwa propMap.putAll(nodeProperties); if (nodeProperties.get(ForwardingMode.name) != null) { ForwardingMode mode = (ForwardingMode) nodeProperties.get(ForwardingMode.name); - proactiveForwarding = mode.isProactive(); + forwardingModeChanged = mode.isProactive(); } } } @@ -1023,28 +1021,35 @@ public class SwitchManager implements ISwitchManager, IConfigurationContainerAwa Property defaultMode = new ForwardingMode(ForwardingMode.REACTIVE_FORWARDING); propMap.put(ForwardingMode.name, defaultMode); } - boolean result = false; - if (propMapCurr == null) { - if (nodeProps.putIfAbsent(node, propMap) == null) { - result = true; - } + + boolean propsAdded = false; + // Attempt initial add + if (nodeProps.putIfAbsent(node, propMap) == null) { + propsAdded = true; + + /* Notify listeners only for initial node addition + * to avoid expensive tasks triggered by redundant notifications + */ + notifyNode(node, UpdateType.ADDED, propMap); } else { - result = nodeProps.replace(node, propMapCurr, propMap); + + propsAdded = nodeProps.replace(node, propMapCurr, propMap); + + // check whether forwarding mode changed + if (propMapCurr.get(ForwardingMode.name) != null) { + ForwardingMode mode = (ForwardingMode) propMapCurr.get(ForwardingMode.name); + forwardingModeChanged ^= mode.isProactive(); + } } - if (!result) { - log.debug("Cluster conflict: Conflict while adding the node properties. Node: {} Properties: {}", - node.getID(), props); + if (!propsAdded) { + log.debug("Cluster conflict while adding node {}. Overwriting with latest props: {}", node.getID(), props); addNodeProps(node, propMap); } - // check if span ports are configed + // check if span ports are configured addSpanPorts(node); - - // notify node listeners - notifyNode(node, UpdateType.ADDED, propMap); - // notify proactive mode forwarding - if (proactiveForwarding) { + if (forwardingModeChanged) { notifyModeChange(node, true); } } @@ -1054,7 +1059,12 @@ public class SwitchManager implements ISwitchManager, IConfigurationContainerAwa if (nodeProps == null) { return; } - nodeProps.remove(node); + + if (nodeProps.remove(node) == null) { + log.debug("Received redundant node REMOVED udate for {}. Skipping..", node); + return; + } + nodeConnectorNames.remove(node); Set removeNodeConnectorSet = new HashSet(); for (Map.Entry> entry : nodeConnectorProps.entrySet()) { @@ -1149,6 +1159,13 @@ public class SwitchManager implements ISwitchManager, IConfigurationContainerAwa switch (type) { case ADDED: + // Skip redundant ADDED update (e.g. cluster switch-over) + if (nodeConnectorProps.containsKey(nodeConnector)) { + log.debug("Redundant nodeconnector ADDED for {}, props {} for container {}", + nodeConnector, props, containerName); + update = false; + } + if (props != null) { for (Property prop : props) { addNodeConnectorProp(nodeConnector, prop); @@ -1158,6 +1175,7 @@ public class SwitchManager implements ISwitchManager, IConfigurationContainerAwa addNodeConnectorProp(nodeConnector, null); } + addSpanPort(nodeConnector); break; case CHANGED: @@ -1384,36 +1402,6 @@ public class SwitchManager implements ISwitchManager, IConfigurationContainerAwa return (propMap != null) ? propMap.get(propName) : null; } - private byte[] getHardwareMAC() { - Enumeration nis; - byte[] macAddress = null; - - try { - nis = NetworkInterface.getNetworkInterfaces(); - } catch (SocketException e) { - log.error("Failed to acquire controller MAC: ", e); - return macAddress; - } - - while (nis.hasMoreElements()) { - NetworkInterface ni = nis.nextElement(); - try { - macAddress = ni.getHardwareAddress(); - } catch (SocketException e) { - log.error("Failed to acquire controller MAC: ", e); - } - if (macAddress != null && macAddress.length != 0) { - break; - } - } - if (macAddress == null) { - log.warn("Failed to acquire controller MAC: No physical interface found"); - // This happens when running controller on windows VM, for example - // Try parsing the OS command output - } - return macAddress; - } - @Override public byte[] getControllerMAC() { MacAddress macProperty = (MacAddress)controllerProps.get(MacAddress.name); @@ -1772,6 +1760,16 @@ public class SwitchManager implements ISwitchManager, IConfigurationContainerAwa } } + public void setControllerProperties(IControllerProperties controllerProperties) { + log.trace("Got controller properties set request {}", controllerProperties); + this.controllerProperties = controllerProperties; + } + + public void unsetControllerProperties(IControllerProperties controllerProperties) { + log.trace("Got controller properties UNset request"); + this.controllerProperties = null; + } + private void getInventories() { if (inventoryService == null) { log.trace("inventory service not avaiable"); @@ -2026,9 +2024,9 @@ public class SwitchManager implements ISwitchManager, IConfigurationContainerAwa // only add if span is configured on this nodeConnector for (SpanConfig conf : getSpanConfigList(nodeConnector.getNode())) { if (conf.getPortArrayList().contains(nodeConnector)) { - List ncLists = new ArrayList(); - ncLists.add(nodeConnector); - addSpanPorts(nodeConnector.getNode(), ncLists); + List ncList = new ArrayList(); + ncList.add(nodeConnector); + addSpanPorts(nodeConnector.getNode(), ncList); return; } } @@ -2149,7 +2147,7 @@ public class SwitchManager implements ISwitchManager, IConfigurationContainerAwa public Set getConfiguredNotConnectedSwitches() { Set configuredNotConnectedSwitches = new HashSet(); if (this.inventoryService == null) { - log.trace("inventory service not avaiable"); + log.trace("inventory service not available"); return configuredNotConnectedSwitches; }