*/
package org.opendaylight.ovsdb.plugin;
-import io.netty.channel.Channel;
import io.netty.channel.ChannelHandler;
import java.io.IOException;
import java.net.InetAddress;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import org.opendaylight.controller.sal.connection.IPluginInConnectionService;
import org.opendaylight.controller.sal.core.Node;
import org.opendaylight.controller.sal.core.Property;
-import org.opendaylight.controller.sal.utils.ServiceHelper;
import org.opendaylight.controller.sal.utils.Status;
import org.opendaylight.controller.sal.utils.StatusCode;
import org.opendaylight.ovsdb.lib.MonitorCallBack;
protected static final Logger logger = LoggerFactory.getLogger(ConnectionService.class);
// Properties that can be set in config.ini
- private static final String OVSDB_LISTENPORT = "ovsdb.listenPort";
private static final Integer defaultOvsdbPort = 6640;
private OvsdbConnection connectionLib;
- private static Integer ovsdbListenPort = defaultOvsdbPort;
- private ConcurrentMap<String, Connection> ovsdbConnections;
+ private ConcurrentMap<String, Connection> ovsdbConnections = new ConcurrentHashMap<String, Connection>();
private List<ChannelHandler> handlers = null;
private InventoryServiceInternal inventoryServiceInternal;
- private Channel serverListenChannel = null;
public InventoryServiceInternal getInventoryServiceInternal() {
return inventoryServiceInternal;
}
public void init() {
- ovsdbConnections = new ConcurrentHashMap<String, Connection>();
- int listenPort = defaultOvsdbPort;
- String portString = System.getProperty(OVSDB_LISTENPORT);
- if (portString != null) {
- listenPort = Integer.decode(portString).intValue();
- }
- ovsdbListenPort = listenPort;
}
/**
* the services provided by the class are registered in the service registry
*/
void start() {
+ Collection<OvsdbClient> connections = connectionLib.getConnections();
+ for (OvsdbClient client : connections) {
+ this.connected(client);
+ }
}
/**
for (Connection connection : ovsdbConnections.values()) {
connection.disconnect();
}
- serverListenChannel.disconnect();
}
@Override
Connection connection = ovsdbConnections.get(identifier);
if (connection != null) {
ovsdbConnections.remove(identifier);
- return connection.disconnect();
+ connection.disconnect();
+ inventoryServiceInternal.removeNode(node);
+ return new Status(StatusCode.SUCCESS);
} else {
return new Status(StatusCode.NOTFOUND);
}
Connection connection = ovsdbConnections.get(identifier);
OvsdbClient client = connection.getClient();
if (dbSchema == null) {
- logger.error("Unable to get Database Schema for the ovsdb connection : {} , database : {}", client.getConnectionInfo(), dbSchema.getName());
+ logger.error("Unable to get Database Schema for the ovsdb connection : {}", client.getConnectionInfo());
return null;
}
Set<String> tables = dbSchema.getTables();
public void connected(OvsdbClient client) {
String identifier = getConnectionIdentifier(client);
try {
- ConnectionService connection = (ConnectionService)ServiceHelper.getGlobalInstance(IConnectionServiceInternal.class, this);
- Node node = connection.handleNewConnection(identifier, client);
+ this.handleNewConnection(identifier, client);
} catch (InterruptedException | ExecutionException e) {
e.printStackTrace();
}
@Override
public void disconnected(OvsdbClient client) {
+ Connection connection = ovsdbConnections.get(this.getConnectionIdentifier(client));
+ if (connection == null) return;
+ this.disconnect(connection.getNode());
}
}
.getLogger(InventoryService.class);
private final Set<IPluginOutInventoryService> pluginOutInventoryServices =
new CopyOnWriteArraySet<IPluginOutInventoryService>();
- private ConcurrentMap<Node, Map<String, Property>> nodeProps;
- private ConcurrentMap<NodeConnector, Map<String, Property>> nodeConnectorProps;
+ private ConcurrentMap<Node, Map<String, Property>> nodeProps = new ConcurrentHashMap<Node, Map<String, Property>>();
+ private ConcurrentMap<NodeConnector, Map<String, Property>> nodeConnectorProps = new ConcurrentHashMap<NodeConnector, Map<String, Property>>();
private ConcurrentMap<Node, NodeDB> dbCache = Maps.newConcurrentMap();
private ScheduledExecutorService executor;
private OVSDBConfigService configurationService;
*
*/
public void init() {
- nodeProps = new ConcurrentHashMap<Node, Map<String, Property>>();
- nodeConnectorProps = new ConcurrentHashMap<NodeConnector, Map<String, Property>>();
Node.NodeIDType.registerIDType("OVS", String.class);
NodeConnector.NodeConnectorIDType.registerIDType("OVS", String.class, "OVS");
this.executor = Executors.newSingleThreadScheduledExecutor();
configurationService = null;
}
- /**
- * Retrieve nodes from openflow
- */
@Override
public ConcurrentMap<Node, Map<String, Property>> getNodeProps() {
return nodeProps;
}
- /**
- * Retrieve nodeConnectors from openflow
- */
@Override
public ConcurrentMap<NodeConnector, Map<String, Property>> getNodeConnectorProps(
Boolean refresh) {