-
/*
* Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
*
private ConcurrentMap<InetAddress, Subnet> subnets; // set of Subnets keyed by the InetAddress
private ConcurrentMap<String, SubnetConfig> subnetsConfigList;
private ConcurrentMap<Integer, SpanConfig> spanConfigList;
- private ConcurrentMap<String, SwitchConfig> nodeConfigList; // manually configured parameters for the node, like name and tier
+ private ConcurrentMap<String, SwitchConfig> nodeConfigList; // manually configured parameters for the node like name and tier
private ConcurrentMap<Long, String> configSaveEvent;
- private ConcurrentMap<Node, Map<String, Property>> nodeProps; // properties are maintained in default container only
- private ConcurrentMap<NodeConnector, Map<String, Property>> nodeConnectorProps; // properties are maintained in default container only
+ private ConcurrentMap<Node, Map<String, Property>> nodeProps; // properties are maintained in global container only
+ private ConcurrentMap<NodeConnector, Map<String, Property>> nodeConnectorProps; // properties are maintained in global container only
private ConcurrentMap<Node, Map<String, NodeConnector>> nodeConnectorNames;
private IInventoryService inventoryService;
private Set<ISwitchManagerAware> switchManagerAware = Collections
private IClusterContainerServices clusterContainerService = null;
private String containerName = null;
private boolean isDefaultContainer = true;
-
+
public enum ReasonCode {
SUCCESS("Success"), FAILURE("Failure"), INVALID_CONF(
"Invalid Configuration"), EXIST("Entry Already Exist"), CONFLICT(
try {
((ISwitchManagerAware) subAware).subnetNotify(sub, add);
} catch (Exception e) {
- log.error("Failed to notify Subnet change", e);
+ log.error("Failed to notify Subnet change {}",
+ e.getMessage());
}
}
}
try {
((ISpanAware) sa).spanUpdate(node, ports, add);
} catch (Exception e) {
- log.error("Failed to notify Span Interface change", e);
+ log.error("Failed to notify Span Interface change {}",
+ e.getMessage());
}
}
}
try {
service.modeChangeNotify(node, proactive);
} catch (Exception e) {
- log.error("Failed to notify Subnet change", e);
+ log.error("Failed to notify Subnet change {}",
+ e.getMessage());
}
}
}
}
@SuppressWarnings("deprecation")
- private void allocateCaches() {
+ private void allocateCaches() {
if (this.clusterContainerService == null) {
- log.info("un-initialized clusterContainerService, can't create cache");
+ log.warn("un-initialized clusterContainerService, can't create cache");
return;
}
try {
clusterContainerService.createCache(
- "switchmanager.subnetsConfigList", EnumSet
- .of(IClusterServices.cacheMode.NON_TRANSACTIONAL));
+ "switchmanager.subnetsConfigList",
+ EnumSet.of(IClusterServices.cacheMode.NON_TRANSACTIONAL));
clusterContainerService.createCache("switchmanager.spanConfigList",
EnumSet.of(IClusterServices.cacheMode.NON_TRANSACTIONAL));
clusterContainerService.createCache("switchmanager.nodeConfigList",
clusterContainerService.createCache("switchmanager.subnets",
EnumSet.of(IClusterServices.cacheMode.NON_TRANSACTIONAL));
clusterContainerService.createCache(
- "switchmanager.configSaveEvent", EnumSet
- .of(IClusterServices.cacheMode.NON_TRANSACTIONAL));
+ "switchmanager.configSaveEvent",
+ EnumSet.of(IClusterServices.cacheMode.NON_TRANSACTIONAL));
clusterContainerService.createCache("switchmanager.nodeProps",
EnumSet.of(IClusterServices.cacheMode.NON_TRANSACTIONAL));
clusterContainerService.createCache(
- "switchmanager.nodeConnectorProps", EnumSet
- .of(IClusterServices.cacheMode.NON_TRANSACTIONAL));
+ "switchmanager.nodeConnectorProps",
+ EnumSet.of(IClusterServices.cacheMode.NON_TRANSACTIONAL));
clusterContainerService.createCache(
- "switchmanager.nodeConnectorNames", EnumSet
- .of(IClusterServices.cacheMode.NON_TRANSACTIONAL));
+ "switchmanager.nodeConnectorNames",
+ EnumSet.of(IClusterServices.cacheMode.NON_TRANSACTIONAL));
} catch (CacheConfigException cce) {
log.error("\nCache configuration invalid - check cache mode");
} catch (CacheExistException ce) {
@SuppressWarnings({ "unchecked", "deprecation" })
private void retrieveCaches() {
if (this.clusterContainerService == null) {
- log
- .info("un-initialized clusterContainerService, can't create cache");
+ log.info("un-initialized clusterContainerService, can't create cache");
return;
}
}
@SuppressWarnings("deprecation")
- private void destroyCaches(String container) {
+ private void destroyCaches(String container) {
if (this.clusterContainerService == null) {
- log
- .info("un-initialized clusterContainerService, can't create cache");
+ log.info("un-initialized clusterContainerService, can't create cache");
return;
}
Subnet newSubnet = new Subnet(conf);
Set<InetAddress> IPs = subnets.keySet();
if (IPs == null) {
- return new Status(StatusCode.SUCCESS, null);
+ return new Status(StatusCode.SUCCESS, null);
}
for (InetAddress i : IPs) {
Subnet existingSubnet = subnets.get(i);
private Status addRemoveSubnet(SubnetConfig conf, boolean add) {
// Valid config check
if (!conf.isValidConfig()) {
- String msg = "Invalid Subnet configuration";
+ String msg = "Invalid Subnet configuration";
log.warn(msg);
return new Status(StatusCode.BADREQUEST, msg);
}
if (add) {
// Presence check
if (subnetsConfigList.containsKey(conf.getName())) {
- return new Status(StatusCode.CONFLICT,
- "Same subnet config already exists");
+ return new Status(StatusCode.CONFLICT,
+ "Same subnet config already exists");
}
// Semantyc check
Status rc = semanticCheck(conf);
return new Status(StatusCode.NOTFOUND, "Subnet does not exist");
}
if (!conf.isValidSwitchPort(switchPorts)) {
- return new Status(StatusCode.BADREQUEST, "Invalid switchports");
+ return new Status(StatusCode.BADREQUEST, "Invalid switchports");
}
conf.addNodeConnectors(switchPorts);
// Update Configuration
SubnetConfig conf = subnetsConfigList.get(name);
if (conf == null) {
- return new Status(StatusCode.NOTFOUND, "Subnet does not exist");
+ return new Status(StatusCode.NOTFOUND, "Subnet does not exist");
}
conf.removeNodeConnectors(switchPorts);
propMap.put(tier.getName(), tier);
addNodeProps(node, propMap);
- log.info("Set Node {}'s Mode to {}", nodeId, cfgObject
- .getMode());
+ log.info("Set Node {}'s Mode to {}", nodeId,
+ cfgObject.getMode());
if (modeChange) {
notifyModeChange(node, cfgObject.isProactive());
}
}
} catch (Exception e) {
- log.debug("updateSwitchConfig: {}", e);
+ log.debug("updateSwitchConfig: {}", e.getMessage());
}
}
public Status addSpanConfig(SpanConfig conf) {
// Valid config check
if (!conf.isValidConfig()) {
- String msg = "Invalid Span configuration";
+ String msg = "Invalid Span configuration";
log.warn(msg);
return new Status(StatusCode.BADREQUEST, msg);
}
// Presence check
if (spanConfigList.containsKey(conf.hashCode())) {
- return new Status(StatusCode.CONFLICT, "Same span config exists");
+ return new Status(StatusCode.CONFLICT, "Same span config exists");
}
// Update database and notify clients
String nodeId = node.toString();
for (SwitchConfig conf : nodeConfigList.values()) {
if (conf.getNodeId().equals(nodeId)) {
- Property description = new Description(conf.getNodeDescription());
+ Property description = new Description(
+ conf.getNodeDescription());
propMap.put(description.getName(), description);
Property tier = new Tier(Integer.parseInt(conf.getTier()));
propMap.put(tier.getName(), tier);
// notify node listeners
notifyNode(node, UpdateType.ADDED, propMap);
-
+
// notify proactive mode forwarding
if (proactiveForwarding) {
- notifyModeChange(node, true);
+ notifyModeChange(node, true);
}
}
Set<Node> nodes = getNodes();
if (nodes != null) {
for (Node node : nodes) {
- if (id.equals((Long)node.getID())) {
+ if (id.equals((Long) node.getID())) {
return node;
}
}
/*
* Returns a copy of a list of properties for a given node
- *
+ *
* (non-Javadoc)
- * @see org.opendaylight.controller.switchmanager.ISwitchManager#getNodeProps(org.opendaylight.controller.sal.core.Node)
+ *
+ * @see
+ * org.opendaylight.controller.switchmanager.ISwitchManager#getNodeProps
+ * (org.opendaylight.controller.sal.core.Node)
*/
@Override
public Map<String, Property> getNodeProps(Node node) {
} else {
// get it from default container
ISwitchManager defaultSwitchManager = (ISwitchManager) ServiceHelper
- .getInstance(ISwitchManager.class, GlobalConstants.DEFAULT
- .toString(), this);
+ .getInstance(ISwitchManager.class,
+ GlobalConstants.DEFAULT.toString(), this);
return defaultSwitchManager.getNodeProps(node);
}
}
public Status removeNodeProp(Node node, String propName) {
Map<String, Property> propMap = getNodeProps(node);
if (propMap != null) {
- propMap.remove(propName);
- this.nodeProps.put(node, propMap);
+ propMap.remove(propName);
+ this.nodeProps.put(node, propMap);
}
return new Status(StatusCode.SUCCESS, null);
}
Set<NodeConnector> nodeConnectorSet = new HashSet<NodeConnector>();
for (NodeConnector nodeConnector : nodeConnectorProps.keySet()) {
- if (((Long) nodeConnector.getNode().getID())
- .longValue() != (Long) node.getID())
+ if (((Long) nodeConnector.getNode().getID()).longValue() != (Long) node
+ .getID())
continue;
if (isNodeConnectorEnabled(nodeConnector))
nodeConnectorSet.add(nodeConnector);
Set<NodeConnector> nodeConnectorSet = new HashSet<NodeConnector>();
for (NodeConnector nodeConnector : nodeConnectorProps.keySet()) {
- if (((Long) nodeConnector.getNode().getID())
- .longValue() != (Long) node.getID())
+ if (((Long) nodeConnector.getNode().getID()).longValue() != (Long) node
+ .getID())
continue;
nodeConnectorSet.add(nodeConnector);
}
}
/*
- * testing utility function which assumes we are dealing with OF Node nodeconnectors only
+ * testing utility function which assumes we are dealing with OF Node
+ * nodeconnectors only
*/
@SuppressWarnings("unused")
private Set<Long> getEnabledNodeConnectorIds(Node node) {
} else {
// get it from default container
ISwitchManager defaultSwitchManager = (ISwitchManager) ServiceHelper
- .getInstance(ISwitchManager.class, GlobalConstants.DEFAULT
- .toString(), this);
+ .getInstance(ISwitchManager.class,
+ GlobalConstants.DEFAULT.toString(), this);
return defaultSwitchManager.getNodeConnectorProps(nodeConnector);
}
}
/**
* Adds a node connector and its property if any
*
- * @param nodeConnector {@link org.opendaylight.controller.sal.core.NodeConnector}
- * @param propName name of {@link org.opendaylight.controller.sal.core.Property}
+ * @param nodeConnector
+ * {@link org.opendaylight.controller.sal.core.NodeConnector}
+ * @param propName
+ * name of {@link org.opendaylight.controller.sal.core.Property}
* @return success or failed reason
*/
@Override
- public Status addNodeConnectorProp(NodeConnector nodeConnector, Property prop) {
+ public Status addNodeConnectorProp(NodeConnector nodeConnector,
+ Property prop) {
Map<String, Property> propMap = getNodeConnectorProps(nodeConnector);
if (propMap == null) {
propMap = new HashMap<String, Property>();
}
- // Just add the nodeConnector if prop is not available (in a non-default container)
+ // Just add the nodeConnector if prop is not available (in a non-default
+ // container)
if (prop == null) {
nodeConnectorProps.put(nodeConnector, propMap);
return new Status(StatusCode.SUCCESS, null);
/**
* Removes one property of a node connector
*
- * @param nodeConnector {@link org.opendaylight.controller.sal.core.NodeConnector}
- * @param propName name of {@link org.opendaylight.controller.sal.core.Property}
+ * @param nodeConnector
+ * {@link org.opendaylight.controller.sal.core.NodeConnector}
+ * @param propName
+ * name of {@link org.opendaylight.controller.sal.core.Property}
* @return success or failed reason
*/
@Override
- public Status removeNodeConnectorProp(NodeConnector nodeConnector, String propName) {
+ public Status removeNodeConnectorProp(NodeConnector nodeConnector,
+ String propName) {
Map<String, Property> propMap = getNodeConnectorProps(nodeConnector);
if (propMap == null) {
- /* Nothing to remove */
+ /* Nothing to remove */
return new Status(StatusCode.SUCCESS, null);
}
/**
* Removes all the properties of a node connector
*
- * @param nodeConnector {@link org.opendaylight.controller.sal.core.NodeConnector}
+ * @param nodeConnector
+ * {@link org.opendaylight.controller.sal.core.NodeConnector}
* @return success or failed reason
*/
@Override
/**
* Function called by the dependency manager when all the required
* dependencies are satisfied
- *
+ *
*/
void init(Component c) {
Dictionary<?, ?> props = c.getServiceProperties();
if (props != null) {
this.containerName = (String) props.get("containerName");
- log.trace("Running containerName:" + this.containerName);
+ log.trace("Running containerName: {}", this.containerName);
} else {
// In the Global instance case the containerName is empty
this.containerName = "";
}
/**
- * Function called by the dependency manager when at least one
- * dependency become unsatisfied or when the component is shutting
- * down because for example bundle is being stopped.
- *
+ * Function called by the dependency manager when at least one dependency
+ * become unsatisfied or when the component is shutting down because for
+ * example bundle is being stopped.
+ *
*/
void destroy() {
shutDown();
}
/**
- * Function called by dependency manager after "init ()" is called
- * and after the services provided by the class are registered in
- * the service registry
- *
+ * Function called by dependency manager after "init ()" is called and after
+ * the services provided by the class are registered in the service registry
+ *
*/
void start() {
// OSGI console
}
/**
- * Function called after registered the
- * service in OSGi service registry.
+ * Function called after registered the service in OSGi service registry.
*/
void started() {
// solicit for existing inventories
}
/**
- * Function called by the dependency manager before the services
- * exported by the component are unregistered, this will be
- * followed by a "destroy ()" calls
- *
+ * Function called by the dependency manager before the services exported by
+ * the component are unregistered, this will be followed by a "destroy ()"
+ * calls
+ *
*/
void stop() {
}
return;
}
for (Node node : nodeSet) {
- Description desc = ((Description) getNodeProp(node, Description.propertyName));
+ Description desc = ((Description) getNodeProp(node,
+ Description.propertyName));
Tier tier = ((Tier) getNodeProp(node, Tier.TierPropName));
String nodeName = (desc == null) ? "" : desc.getValue();
int tierNum = (tier == null) ? 0 : tier.getValue();
- ci.println(node + " " + node.getType()
- + " " + nodeName + " " + tierNum);
+ ci.println(node + " " + node.getType() + " "
+ + nodeName + " " + tierNum);
}
ci.println("Total number of Nodes: " + nodeSet.size());
}
}
ci.println(nodeConnector
- + " "
- + ((nodeConnectorName == null) ? ""
- : nodeConnectorName) + "("
- + nodeConnector.getID() + ")");
+ + " "
+ + ((nodeConnectorName == null) ? "" : nodeConnectorName)
+ + "(" + nodeConnector.getID() + ")");
}
- ci.println("Total number of NodeConnectors: " + nodeConnectorSet.size());
+ ci.println("Total number of NodeConnectors: "
+ + nodeConnectorSet.size());
}
}
@Override
public boolean isSpecial(NodeConnector p) {
- if (p.getType().equals(NodeConnectorIDType.CONTROLLER) ||
- p.getType().equals(NodeConnectorIDType.ALL) ||
- p.getType().equals(NodeConnectorIDType.SWSTACK) ||
- p.getType().equals(NodeConnectorIDType.HWPATH)) {
+ if (p.getType().equals(NodeConnectorIDType.CONTROLLER)
+ || p.getType().equals(NodeConnectorIDType.ALL)
+ || p.getType().equals(NodeConnectorIDType.SWSTACK)
+ || p.getType().equals(NodeConnectorIDType.HWPATH)) {
return true;
}
return false;
return saveSwitchConfig();
}
- /**
- * Creates a Name/Tier/Bandwidth Property object based on given property
- * name and value. Other property types are not supported yet.
- *
- * @param propName Name of the Property
- * @param propValue Value of the Property
- * @return {@link org.opendaylight.controller.sal.core.Property}
- */
- @Override
- public Property createProperty(String propName, String propValue) {
- if (propName == null) {
- log.debug("propName is null");
- return null;
- }
- if (propValue == null) {
- log.debug("propValue is null");
- return null;
- }
-
- try {
- if (propName.equalsIgnoreCase(Description.propertyName)) {
- return new Description(propValue);
- } else if (propName.equalsIgnoreCase(Tier.TierPropName)) {
- int tier = Integer.parseInt(propValue);
- return new Tier(tier);
- } else if (propName.equalsIgnoreCase(Bandwidth.BandwidthPropName)) {
- long bw = Long.parseLong(propValue);
- return new Bandwidth(bw);
- } else {
- log.debug("Not able to create {} property", propName);
- }
- } catch (Exception e) {
- log.debug(e.getMessage());
- }
-
- return null;
- }
-
- @Override
- public String getNodeDescription(Node node) {
- // Check first if user configured a name
+ /**
+ * Creates a Name/Tier/Bandwidth Property object based on given property
+ * name and value. Other property types are not supported yet.
+ *
+ * @param propName
+ * Name of the Property
+ * @param propValue
+ * Value of the Property
+ * @return {@link org.opendaylight.controller.sal.core.Property}
+ */
+ @Override
+ public Property createProperty(String propName, String propValue) {
+ if (propName == null) {
+ log.debug("propName is null");
+ return null;
+ }
+ if (propValue == null) {
+ log.debug("propValue is null");
+ return null;
+ }
+
+ try {
+ if (propName.equalsIgnoreCase(Description.propertyName)) {
+ return new Description(propValue);
+ } else if (propName.equalsIgnoreCase(Tier.TierPropName)) {
+ int tier = Integer.parseInt(propValue);
+ return new Tier(tier);
+ } else if (propName.equalsIgnoreCase(Bandwidth.BandwidthPropName)) {
+ long bw = Long.parseLong(propValue);
+ return new Bandwidth(bw);
+ } else {
+ log.debug("Not able to create {} property", propName);
+ }
+ } catch (Exception e) {
+ log.debug("createProperty caught exception {}", e.getMessage());
+ }
+
+ return null;
+ }
+
+ @Override
+ public String getNodeDescription(Node node) {
+ // Check first if user configured a name
SwitchConfig config = getSwitchConfig(node.toString());
if (config != null) {
- String configuredDesc = config.getNodeDescription();
- if (configuredDesc != null && !configuredDesc.isEmpty()) {
- return configuredDesc;
- }
+ String configuredDesc = config.getNodeDescription();
+ if (configuredDesc != null && !configuredDesc.isEmpty()) {
+ return configuredDesc;
+ }
}
-
+
// No name configured by user, get the node advertised name
- Description desc = (Description) getNodeProp(node, Description.propertyName);
- return (desc == null /*|| desc.getValue().equalsIgnoreCase("none")*/) ?
- "" : desc.getValue();
+ Description desc = (Description) getNodeProp(node,
+ Description.propertyName);
+ return (desc == null /* || desc.getValue().equalsIgnoreCase("none") */) ? ""
+ : desc.getValue();
}
}