// export the service
c.setInterface(
new String[] { IPluginInInventoryService.class.getName(),
- IStatisticsListener.class.getName(),
IInventoryShimInternalListener.class.getName() },
null);
}
if (imp.equals(InventoryServiceShim.class)) {
- c.setInterface(new String[] { IContainerListener.class.getName() },
- null);
+ c.setInterface(new String[] { IContainerListener.class.getName(),
+ IStatisticsListener.class.getName()}, null);
c.add(createServiceDependency()
.setService(IController.class, "(name=Controller)")
import org.apache.felix.dm.Component;
import org.opendaylight.controller.protocol_plugin.openflow.IInventoryShimInternalListener;
-import org.opendaylight.controller.protocol_plugin.openflow.IStatisticsListener;
import org.opendaylight.controller.protocol_plugin.openflow.core.IController;
import org.opendaylight.controller.protocol_plugin.openflow.core.ISwitch;
import org.opendaylight.controller.sal.core.Actions;
import org.opendaylight.controller.sal.core.Buffers;
import org.opendaylight.controller.sal.core.Capabilities;
import org.opendaylight.controller.sal.core.ConstructionException;
-import org.opendaylight.controller.sal.core.Description;
import org.opendaylight.controller.sal.core.Node;
import org.opendaylight.controller.sal.core.Node.NodeIDType;
import org.opendaylight.controller.sal.core.NodeConnector;
import org.opendaylight.controller.sal.inventory.IPluginInInventoryService;
import org.opendaylight.controller.sal.inventory.IPluginOutInventoryService;
import org.opendaylight.controller.sal.utils.GlobalConstants;
-import org.openflow.protocol.statistics.OFDescriptionStatistics;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
*
*/
public class InventoryService implements IInventoryShimInternalListener,
- IPluginInInventoryService, IStatisticsListener {
+ IPluginInInventoryService {
protected static final Logger logger = LoggerFactory
.getLogger(InventoryService.class);
private Set<IPluginOutInventoryService> pluginOutInventoryServices = Collections
try {
node = new Node(NodeIDType.OPENFLOW, id);
} catch (ConstructionException e) {
- logger.error("",e);
+ logger.error("", e);
}
return node;
@Override
public ConcurrentMap<NodeConnector, Map<String, Property>> getNodeConnectorProps(
Boolean refresh) {
- if (nodeConnectorProps == null)
+ if (nodeConnectorProps == null) {
return null;
+ }
if (isDefaultContainer && refresh) {
Map<Long, ISwitch> switches = controller.getSwitches();
switch (type) {
case ADDED:
case CHANGED:
- if (propMap == null)
+ if (propMap == null) {
propMap = new HashMap<String, Property>();
-
+ }
if (props != null) {
for (Property prop : props) {
propMap.put(prop.getName(), prop);
}
private void addNode(Node node, Set<Property> props) {
- logger.trace("{} added", node);
- if (nodeProps == null)
+ logger.trace("{} added, props: {}", node, props);
+ if (nodeProps == null) {
return;
+ }
// update local cache
Map<String, Property> propMap = new HashMap<String, Property>();
}
}
}
-
- private void updateSwitchProperty(Long switchId, Set<Property> propSet) {
- // update local cache
- Node node = OFSwitchToNode(controller.getSwitch(switchId));
- Map<String, Property> propMap = nodeProps.get(node);
- if (propMap == null) {
- propMap = new HashMap<String, Property>();
+
+ private void updateNode(Node node, Set<Property> properties) {
+ logger.trace("{} updated, props: {}", node, properties);
+ if (nodeProps == null || !nodeProps.containsKey(node) ||
+ properties == null || properties.isEmpty()) {
+ return;
}
- boolean change = false;
- for (Property prop : propSet) {
- String propertyName = prop.getName();
- Property currentProp = propMap.get(propertyName);
- if (!prop.equals(currentProp)) {
- change = true;
- propMap.put(propertyName, prop);
+ // Update local cache with new properties
+ Set<Property> newProperties = new HashSet<Property>(properties.size());
+ Map<String, Property> propertyMap = nodeProps.get(node);
+ for (Property property : properties) {
+ String name = property.getName();
+ Property currentProperty = propertyMap.get(name);
+ if (!property.equals(currentProperty)) {
+ propertyMap.put(name, property);
+ newProperties.add(property);
}
}
- nodeProps.put(node, propMap);
- // Update sal if any of the properties has changed
- if (change) {
+ // Update SAL if we got new properties
+ if (!newProperties.isEmpty()) {
synchronized (pluginOutInventoryServices) {
for (IPluginOutInventoryService service : pluginOutInventoryServices) {
- service.updateNode(node, UpdateType.CHANGED, propSet);
+ service.updateNode(node, UpdateType.CHANGED, newProperties);
}
}
}
case REMOVED:
removeNode(node);
break;
+ case CHANGED:
+ updateNode(node, props);
+ break;
default:
break;
}
}
- @Override
- public void descriptionRefreshed(Long switchId,
- OFDescriptionStatistics descriptionStats) {
-
- Set<Property> propSet = new HashSet<Property>(1);
- Description desc = new Description(
- descriptionStats.getDatapathDescription());
- propSet.add(desc);
- this.updateSwitchProperty(switchId, propSet);
- }
}
import org.opendaylight.controller.protocol_plugin.openflow.IInventoryShimExternalListener;
import org.opendaylight.controller.protocol_plugin.openflow.IInventoryShimInternalListener;
+import org.opendaylight.controller.protocol_plugin.openflow.IStatisticsListener;
import org.opendaylight.controller.protocol_plugin.openflow.core.IController;
import org.opendaylight.controller.protocol_plugin.openflow.core.IMessageListener;
import org.opendaylight.controller.protocol_plugin.openflow.core.ISwitch;
import org.opendaylight.controller.sal.core.Capabilities;
import org.opendaylight.controller.sal.core.ConstructionException;
import org.opendaylight.controller.sal.core.ContainerFlow;
+import org.opendaylight.controller.sal.core.Description;
import org.opendaylight.controller.sal.core.IContainerListener;
import org.opendaylight.controller.sal.core.Node;
import org.opendaylight.controller.sal.core.Node.NodeIDType;
import org.openflow.protocol.OFPortStatus;
import org.openflow.protocol.OFPortStatus.OFPortReason;
import org.openflow.protocol.OFType;
+import org.openflow.protocol.statistics.OFDescriptionStatistics;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
*
*/
public class InventoryServiceShim implements IContainerListener,
- IMessageListener, ISwitchStateListener {
+ IMessageListener, ISwitchStateListener, IStatisticsListener {
protected static final Logger logger = LoggerFactory
.getLogger(InventoryServiceShim.class);
private IController controller = null;
inventoryShimInternalListener.updateNode(node, type, null);
}
break;
+ case CHANGED:
+ // Notify only the default Inventory Service
+ inventoryShimDefaultListener = inventoryShimInternalListeners
+ .get(GlobalConstants.DEFAULT.toString());
+ if (inventoryShimDefaultListener != null) {
+ inventoryShimDefaultListener.updateNode(node, type, props);
+ }
+ break;
default:
break;
}
switchAdded(sw);
}
}
+
+ @Override
+ public void descriptionRefreshed(Long switchId,
+ OFDescriptionStatistics descriptionStats) {
+ Node node;
+ try {
+ node = new Node(NodeIDType.OPENFLOW, switchId);
+ } catch (ConstructionException e) {
+ logger.error("{}", e.getMessage());
+ return;
+ }
+
+ Set<Property> properties = new HashSet<Property>(1);
+ Description desc = new Description(
+ descriptionStats.getDatapathDescription());
+ properties.add(desc);
+
+ // Notify all internal and external listeners
+ notifyInventoryShimListener(node, UpdateType.CHANGED, properties);
+ }
+
+
}
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
-import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
/**
* @file Actions.java
@Override
public String toString() {
- return "Actions[" + ReflectionToStringBuilder.toString(this) + "]";
+ return "Actions[" + actionsValue + "]";
}
}
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
-import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
/**
* @file Buffers.java
@Override
public String toString() {
- return "Buffers[" + ReflectionToStringBuilder.toString(this) + "]";
+ return "Buffers[" + buffersValue + "]";
}
}
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
-import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
/**
* @file Capabilities.java
@Override
public String toString() {
- return "Capabilities[" + ReflectionToStringBuilder.toString(this) + "]";
+ return "Capabilities[" + capabilitiesValue + "]";
}
}
package org.opendaylight.controller.sal.core;
-import org.apache.commons.lang3.builder.HashCodeBuilder;
-import org.apache.commons.lang3.builder.EqualsBuilder;
-import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
-
-import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+
+import org.apache.commons.lang3.builder.EqualsBuilder;
+import org.apache.commons.lang3.builder.HashCodeBuilder;
/**
* The class represents Admin Config status
@Override
public String toString() {
- return "Config["+ReflectionToStringBuilder.toString(this)+"]";
+ return "Config["+ configValue +"]";
}
}
package org.opendaylight.controller.sal.core;
-import org.apache.commons.lang3.builder.HashCodeBuilder;
-import org.apache.commons.lang3.builder.EqualsBuilder;
-
import javax.xml.bind.annotation.XmlRootElement;
-import javax.xml.bind.annotation.XmlAccessType;
-import javax.xml.bind.annotation.XmlAccessorType;
-import javax.xml.bind.annotation.XmlElement;
+
+import org.apache.commons.lang3.builder.EqualsBuilder;
+import org.apache.commons.lang3.builder.HashCodeBuilder;
/**
* @file Latency.java
package org.opendaylight.controller.sal.core;
-import org.apache.commons.lang3.builder.HashCodeBuilder;
-import org.apache.commons.lang3.builder.EqualsBuilder;
-import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
-
-import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+
+import org.apache.commons.lang3.builder.EqualsBuilder;
+import org.apache.commons.lang3.builder.HashCodeBuilder;
/**
* The class represents the Name property of an element.
@Override
public String toString() {
- return "Name[" + ReflectionToStringBuilder.toString(this) + "]";
+ return "Name[" + nameValue + "]";
}
}
package org.opendaylight.controller.sal.core;
import java.io.Serializable;
-import org.apache.commons.lang3.builder.HashCodeBuilder;
-import org.apache.commons.lang3.builder.EqualsBuilder;
-import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
+
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlSeeAlso;
-import javax.xml.bind.annotation.XmlElement;
+
+import org.apache.commons.lang3.builder.EqualsBuilder;
+import org.apache.commons.lang3.builder.HashCodeBuilder;
+import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
/**
* @file Property.java
/**
* Private constructor used for JAXB mapping
*/
+ @SuppressWarnings("unused")
private Property() {
this.name = null;
}
package org.opendaylight.controller.sal.core;
-import org.apache.commons.lang3.builder.HashCodeBuilder;
-import org.apache.commons.lang3.builder.EqualsBuilder;
-import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
-
-import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+
+import org.apache.commons.lang3.builder.EqualsBuilder;
+import org.apache.commons.lang3.builder.HashCodeBuilder;
/**
* The class represents the State property of an Edge
@Override
public String toString() {
- return "State[" + ReflectionToStringBuilder.toString(this) + "]";
+ return "State[" + stateValue + "]";
}
}
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
-import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
/**
* @file Tables.java
@Override
public String toString() {
- return "Tables[" + ReflectionToStringBuilder.toString(this) + "]";
+ return "Tables[" + tablesValue + "]";
}
}
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
-import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.builder.EqualsBuilder;
-import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
+import org.apache.commons.lang3.builder.HashCodeBuilder;
/**
* The class represents the Tier property of a node
@Override
public String toString() {
- return "Tier[" + ReflectionToStringBuilder.toString(this) + "]";
+ return "Tier[" + tierValue + "]";
}
}
package org.opendaylight.controller.sal.core;
-import org.apache.commons.lang3.builder.HashCodeBuilder;
-import org.apache.commons.lang3.builder.EqualsBuilder;
-import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
-
-import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+
+import org.apache.commons.lang3.builder.EqualsBuilder;
+import org.apache.commons.lang3.builder.HashCodeBuilder;
/**
* @file TimeStamp.java
@Override
public String toString() {
- return "TimeStamp[" + ReflectionToStringBuilder.toString(this) + "]";
+ return "TimeStamp[" + timestampName + ": " + timestamp +"]";
}
}
package org.opendaylight.controller.sal.core;
-import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
/**
* @file UpdateType.java
public String getName() {
return this.name;
}
-
- @Override
- public String toString() {
- return "UpdateType[" + ReflectionToStringBuilder.toString(this) + "]";
- }
}
}
private void addNode(Node node, Set<Property> props) {
- log.trace("{} added", node);
+ log.trace("{} added, props: {}", node, props);
if (nodeProps == null) {
return;
}
private void removeNode(Node node) {
log.trace("{} removed", node);
- if (nodeProps == null)
+ if (nodeProps == null) {
return;
+ }
nodeProps.remove(node);
// check if span ports need to be cleaned up
}
private void updateNode(Node node, Set<Property> props) {
- log.trace("{} updated", node);
- if (nodeProps == null) {
+ log.trace("{} updated, props: {}", node, props);
+ if (nodeProps == null || !nodeProps.containsKey(node) ||
+ props == null || props.isEmpty()) {
return;
}