import org.opendaylight.ovsdb.integrationtest.ConfigurationBundles;
import org.opendaylight.ovsdb.integrationtest.OvsdbIntegrationTestBase;
import org.opendaylight.ovsdb.lib.OvsdbClient;
+import org.opendaylight.ovsdb.lib.OvsdbConnectionInfo;
+import org.opendaylight.ovsdb.plugin.Connection;
import org.opendaylight.ovsdb.plugin.IConnectionServiceInternal;
import org.opendaylight.ovsdb.plugin.OVSDBConfigService;
import org.ops4j.pax.exam.Configuration;
String portStr = props.getProperty(SERVER_PORT, DEFAULT_SERVER_PORT);
String connectionType = props.getProperty(CONNECTION_TYPE, "active");
+ IConnectionServiceInternal connection = (IConnectionServiceInternal)ServiceHelper.getGlobalInstance(IConnectionServiceInternal.class, this);
// If the connection type is active, controller connects to the ovsdb-server
if (connectionType.equalsIgnoreCase(CONNECTION_TYPE_ACTIVE)) {
if (addressStr == null) {
Map<ConnectionConstants, String> params = new HashMap<ConnectionConstants, String>();
params.put(ConnectionConstants.ADDRESS, addressStr);
params.put(ConnectionConstants.PORT, portStr);
-
- IConnectionServiceInternal connection = (IConnectionServiceInternal)ServiceHelper.getGlobalInstance(IConnectionServiceInternal.class, this);
return connection.connect(IDENTIFIER, params);
+ } else if (connectionType.equalsIgnoreCase(CONNECTION_TYPE_PASSIVE)) {
+ // Wait for 10 seconds for the Passive connection to be initiated by the ovsdb-server.
+ Thread.sleep(10000);
+ List<Node> nodes = connection.getNodes();
+ assertNotNull(nodes);
+ assertTrue(nodes.size() > 0);
+ return nodes.get(0);
}
- fail("Connection parameter ("+CONNECTION_TYPE+") must be active");
+ fail("Connection parameter ("+CONNECTION_TYPE+") must be active or passive");
return null;
}
@Test
public void tableTest() throws Exception {
Thread.sleep(5000);
- IConnectionServiceInternal connection = (IConnectionServiceInternal)ServiceHelper.getGlobalInstance(IConnectionServiceInternal.class, this);
+ IConnectionServiceInternal connectionService = (IConnectionServiceInternal)ServiceHelper.getGlobalInstance(IConnectionServiceInternal.class, this);
// Check for the ovsdb Connection as seen by the Plugin layer
- assertNotNull(connection.getNodes());
- assertTrue(connection.getNodes().size() > 0);
- assertEquals(Node.fromString("OVS|"+IDENTIFIER), connection.getNodes().get(0));
+ assertNotNull(connectionService.getNodes());
+ assertTrue(connectionService.getNodes().size() > 0);
+ Node node = connectionService.getNodes().get(0);
+ Connection connection = connectionService.getConnection(node);
+ OvsdbConnectionInfo connectionInfo = connection.getClient().getConnectionInfo();
+ String identifier = IDENTIFIER;
+ if (connectionInfo.getType().equals(OvsdbConnectionInfo.ConnectionType.PASSIVE)) {
+ identifier = connectionInfo.getRemoteAddress().getHostAddress()+":"+connectionInfo.getRemotePort();
+ }
+ assertEquals(Node.fromString("OVS|"+identifier), connectionService.getNodes().get(0));
- System.out.println("Nodes = "+connection.getNodes());
+ System.out.println("Nodes = "+ connectionService.getNodes());
List<String> tables = ovsdbConfigService.getTables(node);
System.out.println("Tables = "+tables);
Map<String, ColumnSchema> columns = new HashMap<>();
for (Iterator<Map.Entry<String, JsonNode>> iter = json.get("columns").fields(); iter.hasNext(); ) {
Map.Entry<String, JsonNode> column = iter.next();
- logger.debug("%s:%s", tableName, column.getKey());
+ logger.debug("{}:{}", tableName, column.getKey());
columns.put(column.getKey(), ColumnSchema.fromJson(column.getKey(), column.getValue()));
}
import org.opendaylight.controller.sal.utils.INodeConnectorFactory;
import org.opendaylight.controller.sal.utils.INodeFactory;
import org.opendaylight.ovsdb.lib.OvsdbConnection;
-import org.opendaylight.ovsdb.lib.OvsdbConnectionListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
props.put(GlobalConstants.PROTOCOLPLUGINTYPE.toString(), "OVS");
c.setInterface(
new String[] {IPluginInConnectionService.class.getName(),
- IConnectionServiceInternal.class.getName(),
- OvsdbConnectionListener.class.getName()}, props);
+ IConnectionServiceInternal.class.getName()}, props);
+
c.add(createServiceDependency()
.setService(InventoryServiceInternal.class)
.setCallbacks("setInventoryServiceInternal", "unsetInventoryServiceInternal")
public void setOvsdbConnection(OvsdbConnection connectionService) {
connectionLib = connectionService;
+ // It is not correct to register the service here. Rather, we should depend on the
+ // Service created by createServiceDependency() and hook to it via Apache DM.
+ // Using this temporarily till the Service Dependency is resolved.
+ connectionLib.registerForPassiveConnection(this);
}
public void unsetOvsdbConnection(OvsdbConnection connectionService) {
try {
OvsdbClient client = connectionLib.connect(address, port);
- return handleNewConnection(identifier, client, this);
+ return handleNewConnection(identifier, client);
} catch (InterruptedException e) {
logger.error("Thread was interrupted during connect", e);
} catch (ExecutionException e) {
public void notifyNodeDisconnectFromMaster(Node arg0) {
}
- private Node handleNewConnection(String identifier, OvsdbClient client, ConnectionService instance) throws InterruptedException, ExecutionException {
+ private Node handleNewConnection(String identifier, OvsdbClient client) throws InterruptedException, ExecutionException {
Connection connection = new Connection(identifier, client);
Node node = connection.getNode();
ovsdbConnections.put(identifier, connection);
return info.getRemoteAddress().getHostAddress()+":"+info.getRemotePort();
}
+
@Override
public void connected(OvsdbClient client) {
- logger.info("PLUGIN RECEIVED NOW CONNECTION FROM LIBRARY : "+ client.getConnectionInfo().toString());
String identifier = getConnectionIdentifier(client);
try {
- Node node = handleNewConnection(identifier, client, ConnectionService.this);
+ ConnectionService connection = (ConnectionService)ServiceHelper.getGlobalInstance(IConnectionServiceInternal.class, this);
+ Node node = connection.handleNewConnection(identifier, client);
} catch (InterruptedException | ExecutionException e) {
- // TODO Auto-generated catch block
e.printStackTrace();
}
}
@Override
public void disconnected(OvsdbClient client) {
- logger.info("PLUGIN RECEIVED CONNECTION DISCONNECT FROM LIBRARY : "+ client.getConnectionInfo().toString());
}
}