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=674da37afb5676a971905aefc3caf2a84eb2c761;hp=0581aa49ea574a214faf2c78acfbf9ecb449ceb1;hb=82e3a5c7a6d2bbce5dffe0bae63393379a42ac75;hpb=6b64494fd8e4654a298312afb4b8e6e827b75d5d 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 0581aa49ea..674da37afb 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 @@ -106,13 +106,24 @@ public class SwitchManager implements ISwitchManager, IConfigurationContainerAwa private final Set inventoryListeners = Collections .synchronizedSet(new HashSet()); private final Set spanAware = Collections.synchronizedSet(new HashSet()); - private static boolean hostRefresh = true; - private int hostRetryCount = 5; private IClusterContainerServices clusterContainerService = null; private String containerName = null; private boolean isDefaultContainer = true; private static final int REPLACE_RETRY = 1; + /* Information about the default subnet. If there have been no configured subnets, i.e., + * subnets.size() == 0 or subnetsConfigList.size() == 0, then this subnet will be the + * only subnet returned. As soon as a user-configured subnet is created this one will + * vanish. + */ + protected static SubnetConfig DEFAULT_SUBNETCONFIG; + protected static Subnet DEFAULT_SUBNET; + protected static String DEFAULT_SUBNET_NAME = "default (cannot be modifed)"; + static{ + DEFAULT_SUBNETCONFIG = new SubnetConfig(DEFAULT_SUBNET_NAME, "0.0.0.0/0", new ArrayList()); + DEFAULT_SUBNET = new Subnet(DEFAULT_SUBNETCONFIG); + } + public void notifySubnetChange(Subnet sub, boolean add) { synchronized (switchManagerAware) { for (Object subAware : switchManagerAware) { @@ -164,16 +175,11 @@ public class SwitchManager implements ISwitchManager, IConfigurationContainerAwa retrieveCaches(); /* - * Read startup and build database if we have not already gotten the - * configurations synced from another node + * Read startup and build database if we are the coordinator */ - if (subnetsConfigList.isEmpty()) { + if ((clusterContainerService != null) && (clusterContainerService.amICoordinator())) { loadSubnetConfiguration(); - } - if (spanConfigList.isEmpty()) { loadSpanConfiguration(); - } - if (nodeConfigList.isEmpty()) { loadSwitchConfiguration(); } @@ -231,7 +237,7 @@ public class SwitchManager implements ISwitchManager, IConfigurationContainerAwa @SuppressWarnings({ "unchecked" }) private void retrieveCaches() { if (this.clusterContainerService == null) { - log.info("un-initialized clusterContainerService, can't create cache"); + log.warn("un-initialized clusterContainerService, can't create cache"); return; } @@ -297,12 +303,22 @@ public class SwitchManager implements ISwitchManager, IConfigurationContainerAwa @Override public List getSubnetsConfigList() { - return new ArrayList(subnetsConfigList.values()); + // if there are no subnets, return the default subnet + if(subnetsConfigList.size() == 0){ + return Collections.singletonList(DEFAULT_SUBNETCONFIG); + }else{ + return new ArrayList(subnetsConfigList.values()); + } } @Override public SubnetConfig getSubnetConfig(String subnet) { - return subnetsConfigList.get(subnet); + // if there are no subnets, return the default subnet + if(subnetsConfigList.isEmpty() && subnet.equalsIgnoreCase(DEFAULT_SUBNET_NAME)){ + return DEFAULT_SUBNETCONFIG; + }else{ + return subnetsConfigList.get(subnet); + } } private List getSpanConfigList(Node node) { @@ -407,11 +423,11 @@ public class SwitchManager implements ISwitchManager, IConfigurationContainerAwa } private Status semanticCheck(SubnetConfig conf) { - Subnet newSubnet = new Subnet(conf); Set IPs = subnets.keySet(); if (IPs == null) { return new Status(StatusCode.SUCCESS); } + Subnet newSubnet = new Subnet(conf); for (InetAddress i : IPs) { Subnet existingSubnet = subnets.get(i); if ((existingSubnet != null) && !existingSubnet.isMutualExclusive(newSubnet)) { @@ -440,6 +456,10 @@ public class SwitchManager implements ISwitchManager, IConfigurationContainerAwa if (!status.isSuccess()) { return status; } + } else { + if (conf.getName().equalsIgnoreCase(DEFAULT_SUBNET_NAME)) { + return new Status(StatusCode.NOTALLOWED, "The specified subnet gateway cannot be removed"); + } } // Update Database @@ -450,6 +470,16 @@ public class SwitchManager implements ISwitchManager, IConfigurationContainerAwa status = updateConfig(conf, isAdding); if(!status.isSuccess()) { updateDatabase(conf, (!isAdding)); + } else { + // update the listeners + Subnet subnetCurr = subnets.get(conf.getIPAddress()); + Subnet subnet; + if (subnetCurr == null) { + subnet = new Subnet(conf); + } else { + subnet = subnetCurr.clone(); + } + notifySubnetChange(subnet, isAdding); } } @@ -471,6 +501,9 @@ public class SwitchManager implements ISwitchManager, IConfigurationContainerAwa @Override public Status removeSubnet(String name) { + if (name.equalsIgnoreCase(DEFAULT_SUBNET_NAME)) { + return new Status(StatusCode.NOTALLOWED, "The specified subnet gateway cannot be removed"); + } SubnetConfig conf = subnetsConfigList.get(name); if (conf == null) { return new Status(StatusCode.SUCCESS, "Subnet not present"); @@ -648,12 +681,14 @@ public class SwitchManager implements ISwitchManager, IConfigurationContainerAwa @Override public Subnet getSubnetByNetworkAddress(InetAddress networkAddress) { - Subnet sub; - Set indices = subnets.keySet(); - for (InetAddress i : indices) { - sub = subnets.get(i); - if (sub.isSubnetOf(networkAddress)) { - return sub; + // if there are no subnets, return the default subnet + if (subnets.size() == 0) { + return DEFAULT_SUBNET; + } + + for(Map.Entry subnetEntry : subnets.entrySet()) { + if(subnetEntry.getValue().isSubnetOf(networkAddress)) { + return subnetEntry.getValue(); } } return null; @@ -754,7 +789,7 @@ public class SwitchManager implements ISwitchManager, IConfigurationContainerAwa return; } - log.info("Set Node {}'s Mode to {}", nodeId, cfgObject.getMode()); + log.trace("Set Node {}'s Mode to {}", nodeId, cfgObject.getMode()); if (modeChange) { notifyModeChange(node, cfgObject.isProactive()); @@ -1068,8 +1103,7 @@ public class SwitchManager implements ISwitchManager, IConfigurationContainerAwa private void updateNode(Node node, Set props) { log.trace("{} updated, props: {}", node, props); - if (nodeProps == null || !nodeProps.containsKey(node) || - props == null || props.isEmpty()) { + if (nodeProps == null || props == null) { return; } @@ -1184,8 +1218,46 @@ public class SwitchManager implements ISwitchManager, IConfigurationContainerAwa @Override public Set getNodes() { - return (nodeProps != null) ? new HashSet(nodeProps.keySet()) - : new HashSet(); + return (nodeProps != null) ? new HashSet(nodeProps.keySet()) : new HashSet(); + } + + @Override + public Map getControllerProperties() { + return new HashMap(this.controllerProps); + } + + @Override + public Property getControllerProperty(String propertyName) { + if (propertyName != null) { + HashMap propertyMap = new HashMap(this.controllerProps); + return propertyMap.get(propertyName); + } + return null; + } + + @Override + public Status setControllerProperty(Property property) { + if (property != null) { + this.controllerProps.put(property.getName(), property); + return new Status(StatusCode.SUCCESS); + } + return new Status(StatusCode.BADREQUEST, "Invalid property provided when setting property"); + } + + @Override + public Status removeControllerProperty(String propertyName) { + if (propertyName != null) { + if (this.controllerProps.containsKey(propertyName)) { + this.controllerProps.remove(propertyName); + if (!this.controllerProps.containsKey(propertyName)) { + return new Status(StatusCode.SUCCESS); + } + } + String msg = "Unable to remove property " + propertyName + " from Controller"; + return new Status(StatusCode.BADREQUEST, msg); + } + String msg = "Invalid property provided when removing property from Controller"; + return new Status(StatusCode.BADREQUEST, msg); } /* @@ -1232,10 +1304,6 @@ public class SwitchManager implements ISwitchManager, IConfigurationContainerAwa if (nodeProps.replace(node, propMapCurr, propMap)) { return; } - if (!propMapCurr.get(prop.getName()).equals(nodeProps.get(node).get(prop.getName()))) { - log.debug("Cluster conflict: Unable to add property {} to node {}.", prop.getName(), node.getID()); - return; - } } log.warn("Cluster conflict: Unable to add property {} to node {}.", prop.getName(), node.getID()); } @@ -1253,12 +1321,6 @@ public class SwitchManager implements ISwitchManager, IConfigurationContainerAwa if (nodeProps.replace(node, propMapCurr, propMap)) { return new Status(StatusCode.SUCCESS); } - if (!propMapCurr.get(propName).equals(nodeProps.get(node).get(propName))) { - String msg = "Cluster conflict: Unable to remove property " + propName + " for node " - + node.getID(); - return new Status(StatusCode.CONFLICT, msg); - } - } else { return new Status(StatusCode.SUCCESS); } @@ -1385,16 +1447,6 @@ public class SwitchManager implements ISwitchManager, IConfigurationContainerAwa return (macProperty == null) ? null : macProperty.getMacAddress(); } - @Override - public boolean isHostRefreshEnabled() { - return hostRefresh; - } - - @Override - public int getHostRetryCount() { - return hostRetryCount; - } - @Override public NodeConnector getNodeConnector(Node node, String nodeConnectorName) { if (nodeConnectorNames == null) { @@ -1843,15 +1895,18 @@ public class SwitchManager implements ISwitchManager, IConfigurationContainerAwa && (state != null) && (state.getValue() == State.EDGE_UP)); } + @Override + public boolean doesNodeConnectorExist(NodeConnector nc) { + return (nc != null && nodeConnectorProps != null + && nodeConnectorProps.containsKey(nc)); + } + @Override public String getHelp() { StringBuffer help = new StringBuffer(); help.append("---Switch Manager---\n"); help.append("\t pencs - Print enabled node connectors for a given node\n"); help.append("\t pdm - Print switch ports in device map\n"); - help.append("\t snt - Set node tier number\n"); - help.append("\t hostRefresh - Enable/Disable/Query host refresh\n"); - help.append("\t hostRetry - Set host retry count\n"); return help.toString(); } @@ -1934,66 +1989,6 @@ public class SwitchManager implements ISwitchManager, IConfigurationContainerAwa } } - public void _snt(CommandInterpreter ci) { - String st = ci.nextArgument(); - if (st == null) { - ci.println("Please enter node id"); - return; - } - - Node node = Node.fromString(st); - if (node == null) { - ci.println("Please enter node id"); - return; - } - - st = ci.nextArgument(); - if (st == null) { - ci.println("Please enter tier number"); - return; - } - Integer tid = Integer.decode(st); - Tier tier = new Tier(tid); - setNodeProp(node, tier); - } - - public void _hostRefresh(CommandInterpreter ci) { - String mode = ci.nextArgument(); - if (mode == null) { - ci.println("expecting on/off/?"); - return; - } - if (mode.toLowerCase().equals("on")) { - hostRefresh = true; - } else if (mode.toLowerCase().equals("off")) { - hostRefresh = false; - } else if (mode.equals("?")) { - if (hostRefresh) { - ci.println("host refresh is ON"); - } else { - ci.println("host refresh is OFF"); - } - } else { - ci.println("expecting on/off/?"); - } - return; - } - - public void _hostRetry(CommandInterpreter ci) { - String retry = ci.nextArgument(); - if (retry == null) { - ci.println("Please enter a valid number. Current retry count is " - + hostRetryCount); - return; - } - try { - hostRetryCount = Integer.parseInt(retry); - } catch (Exception e) { - ci.println("Please enter a valid number"); - } - return; - } - @Override public byte[] getNodeMAC(Node node) { MacAddress mac = (MacAddress) this.getNodeProp(node, @@ -2093,8 +2088,9 @@ public class SwitchManager implements ISwitchManager, IConfigurationContainerAwa } /** - * Creates a Name/Tier/Bandwidth Property object based on given property - * name and value. Other property types are not supported yet. + * Creates a Name/Tier/Bandwidth/MacAddress(controller property) Property + * object based on given property name and value. Other property types are + * not supported yet. * * @param propName * Name of the Property @@ -2125,7 +2121,10 @@ public class SwitchManager implements ISwitchManager, IConfigurationContainerAwa } else if (propName.equalsIgnoreCase(ForwardingMode.name)) { int mode = Integer.parseInt(propValue); return new ForwardingMode(mode); - } else { + } else if (propName.equalsIgnoreCase(MacAddress.name)){ + return new MacAddress(propValue); + } + else { log.debug("Not able to create {} property", propName); } } catch (Exception e) { @@ -2135,6 +2134,7 @@ public class SwitchManager implements ISwitchManager, IConfigurationContainerAwa return null; } + @SuppressWarnings("deprecation") @Override public String getNodeDescription(Node node) { @@ -2153,4 +2153,25 @@ public class SwitchManager implements ISwitchManager, IConfigurationContainerAwa return (desc == null /* || desc.getValue().equalsIgnoreCase("none") */) ? "" : desc.getValue(); } + + @Override + public Set getConfiguredNotConnectedSwitches() { + Set configuredNotConnectedSwitches = new HashSet(); + if (this.inventoryService == null) { + log.trace("inventory service not avaiable"); + return configuredNotConnectedSwitches; + } + + Set configuredNotConnectedNodes = this.inventoryService.getConfiguredNotConnectedNodes(); + if (configuredNotConnectedNodes != null) { + for (Node node : configuredNotConnectedNodes) { + Switch sw = getSwitchByNode(node); + if (sw != null) { + configuredNotConnectedSwitches.add(sw); + } + } + } + return configuredNotConnectedSwitches; + } + }