X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fswitchmanager%2Fimplementation%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fswitchmanager%2Finternal%2FSwitchManager.java;h=8372f88e7dce895e135debf1daef17e18d02b0f1;hb=refs%2Fchanges%2F04%2F7004%2F2;hp=e457fecfedf9b75d5ec1f59f006d64775472e144;hpb=a771358fc4c140d5f582066556e14c6c4d284f84;p=controller.git 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 e457fecfed..8372f88e7d 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,8 +53,8 @@ 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.ServiceHelper; import org.opendaylight.controller.sal.utils.Status; import org.opendaylight.controller.sal.utils.StatusCode; import org.opendaylight.controller.statisticsmanager.IStatisticsManager; @@ -102,6 +99,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()); @@ -118,6 +116,9 @@ public class SwitchManager implements ISwitchManager, IConfigurationContainerAwa * only subnet returned. As soon as a user-configured subnet is created this one will * vanish. */ + private static final String DISABLE_DEFAULT_SUBNET_PROP = "switchmanager.disableDefaultSubnetGateway"; + private static final String DISABLE_DEFAULT_SUBNET_PROP_VAL = System.getProperty(DISABLE_DEFAULT_SUBNET_PROP); + private static final boolean USE_DEFAULT_SUBNET_GW = !Boolean.valueOf(DISABLE_DEFAULT_SUBNET_PROP_VAL); protected static final SubnetConfig DEFAULT_SUBNETCONFIG; protected static final Subnet DEFAULT_SUBNET; protected static final String DEFAULT_SUBNET_NAME = "default (cannot be modifed)"; @@ -171,13 +172,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); } } } @@ -291,9 +292,9 @@ public class SwitchManager implements ISwitchManager, IConfigurationContainerAwa @Override public List getSubnetsConfigList() { // if there are no subnets, return the default subnet - if(subnetsConfigList.size() == 0){ + if (USE_DEFAULT_SUBNET_GW && subnetsConfigList.isEmpty()) { return Collections.singletonList(DEFAULT_SUBNETCONFIG); - }else{ + } else { return new ArrayList(subnetsConfigList.values()); } } @@ -301,9 +302,9 @@ public class SwitchManager implements ISwitchManager, IConfigurationContainerAwa @Override public SubnetConfig getSubnetConfig(String subnet) { // if there are no subnets, return the default subnet - if(subnetsConfigList.isEmpty() && subnet.equalsIgnoreCase(DEFAULT_SUBNET_NAME)){ + if (USE_DEFAULT_SUBNET_GW && subnetsConfigList.isEmpty() && subnet.equalsIgnoreCase(DEFAULT_SUBNET_NAME)) { return DEFAULT_SUBNETCONFIG; - }else{ + } else { return subnetsConfigList.get(subnet); } } @@ -1017,6 +1018,18 @@ public class SwitchManager implements ISwitchManager, IConfigurationContainerAwa ForwardingMode mode = (ForwardingMode) nodeProperties.get(ForwardingMode.name); forwardingModeChanged = mode.isProactive(); } + } else if ((conf == null) && !(GlobalConstants.DEFAULT.toString().equals(containerName))) { + ISwitchManager defaultSwitchManager = (ISwitchManager) ServiceHelper.getInstance(ISwitchManager.class, GlobalConstants.DEFAULT.toString(), this); + if (defaultSwitchManager != null) { + Property defaultContainerSwitchDesc = (Description) defaultSwitchManager.getNodeProp(node, Description.propertyName); + if (defaultContainerSwitchDesc != null) { + Map descPropMap = new HashMap(); + descPropMap.put(Description.propertyName, defaultContainerSwitchDesc); + conf = new SwitchConfig(nodeId, descPropMap); + updateNodeConfig(conf); + propMap.put(Description.propertyName, defaultContainerSwitchDesc); + } + } } } @@ -1405,36 +1418,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); @@ -1793,6 +1776,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");