package org.opendaylight.controller.protocol_plugin.openflow.internal;
-import java.util.Collections;
-import java.util.Date;
import java.util.Dictionary;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
+import java.util.concurrent.CopyOnWriteArraySet;
import org.apache.felix.dm.Component;
import org.opendaylight.controller.protocol_plugin.openflow.IInventoryProvider;
import org.opendaylight.controller.protocol_plugin.openflow.IInventoryShimInternalListener;
import org.opendaylight.controller.protocol_plugin.openflow.core.IController;
import org.opendaylight.controller.protocol_plugin.openflow.core.ISwitch;
-import org.opendaylight.controller.sal.core.ConstructionException;
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.core.Property;
import org.opendaylight.controller.sal.core.UpdateType;
IPluginInInventoryService, IInventoryProvider {
protected static final Logger logger = LoggerFactory
.getLogger(InventoryService.class);
- private Set<IPluginOutInventoryService> pluginOutInventoryServices = Collections
- .synchronizedSet(new HashSet<IPluginOutInventoryService>());
+ private Set<IPluginOutInventoryService> pluginOutInventoryServices;
private IController controller = null;
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 boolean isDefaultContainer = false;
+ private String containerName = null;
void setController(IController s) {
this.controller = s;
Dictionary props = c.getServiceProperties();
if (props != null) {
- String containerName = (String) props.get("containerName");
+ containerName = (String) props.get("containerName");
isDefaultContainer = containerName.equals(GlobalConstants.DEFAULT
.toString());
}
nodeProps = new ConcurrentHashMap<Node, Map<String, Property>>();
nodeConnectorProps = new ConcurrentHashMap<NodeConnector, Map<String, Property>>();
+ pluginOutInventoryServices = new CopyOnWriteArraySet<IPluginOutInventoryService>();
}
/**
}
}
- protected Node OFSwitchToNode(ISwitch sw) {
- Node node = null;
- Object id = sw.getId();
-
- try {
- node = new Node(NodeIDType.OPENFLOW, id);
- } catch (ConstructionException e) {
- logger.error("", e);
- }
-
- return node;
- }
-
/**
* Retrieve nodes from openflow
*/
@Override
public ConcurrentMap<Node, Map<String, Property>> getNodeProps() {
+ logger.debug("getNodePros for container {}", containerName);
return nodeProps;
}
}
// update sal and discovery
- synchronized (pluginOutInventoryServices) {
- for (IPluginOutInventoryService service : pluginOutInventoryServices) {
- service.updateNodeConnector(nodeConnector, type, props);
- }
+ for (IPluginOutInventoryService service : pluginOutInventoryServices) {
+ service.updateNodeConnector(nodeConnector, type, props);
}
+
}
private void addNode(Node node, Set<Property> props) {
- logger.trace("{} added, props: {}", node, props);
if (nodeProps == null) {
return;
}
+ Set<Node> nodeSet = nodeProps.keySet();
+ if (((props == null) || props.isEmpty()) && (nodeSet != null)
+ && nodeSet.contains(node)) {
+ // node already added
+ return;
+ }
+
+ logger.trace("addNode: {} added, props: {} for container {}",
+ new Object[] { node, props, containerName });
+
// update local cache
- Map<String, Property> propMap = new HashMap<String, Property>();
- for (Property prop : props) {
- propMap.put(prop.getName(), prop);
+ Map<String, Property> propMap = nodeProps.get(node);
+ if (propMap == null) {
+ propMap = new HashMap<String, Property>();
+ }
+
+ if (props != null) {
+ for (Property prop : props) {
+ propMap.put(prop.getName(), prop);
+ }
}
nodeProps.put(node, propMap);
// update sal
- synchronized (pluginOutInventoryServices) {
- for (IPluginOutInventoryService service : pluginOutInventoryServices) {
- service.updateNode(node, UpdateType.ADDED, props);
- }
+ for (IPluginOutInventoryService service : pluginOutInventoryServices) {
+ service.updateNode(node, UpdateType.ADDED, props);
}
}
}
// update sal
- synchronized (pluginOutInventoryServices) {
- for (IPluginOutInventoryService service : pluginOutInventoryServices) {
- service.updateNode(node, UpdateType.REMOVED, null);
- }
+ for (IPluginOutInventoryService service : pluginOutInventoryServices) {
+ service.updateNode(node, UpdateType.REMOVED, null);
}
}
// Update SAL if we got new properties
if (!newProperties.isEmpty()) {
- synchronized (pluginOutInventoryServices) {
- for (IPluginOutInventoryService service : pluginOutInventoryServices) {
- service.updateNode(node, UpdateType.CHANGED, newProperties);
- }
+ for (IPluginOutInventoryService service : pluginOutInventoryServices) {
+ service.updateNode(node, UpdateType.CHANGED, newProperties);
}
}
}