package org.opendaylight.ovsdb.integrationtest;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.io.IOException;
import java.net.InetAddress;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
import java.util.Properties;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
+import org.opendaylight.controller.sal.connection.ConnectionConstants;
+import org.opendaylight.controller.sal.core.Node;
import org.opendaylight.controller.sal.utils.ServiceHelper;
import org.opendaylight.ovsdb.lib.OvsdbClient;
import org.opendaylight.ovsdb.lib.OvsdbConnection;
import org.opendaylight.ovsdb.lib.OvsdbConnectionListener;
+import org.opendaylight.ovsdb.plugin.IConnectionServiceInternal;
public abstract class OvsdbIntegrationTestBase {
protected final static String IDENTIFIER = "TEST";
return props;
}
+ public Node getPluginTestConnection() throws IOException, InterruptedException, ExecutionException, TimeoutException {
+ Properties props = loadProperties();
+ String addressStr = props.getProperty(SERVER_IPADDRESS);
+ 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) {
+ fail(usage());
+ }
+
+ Map<ConnectionConstants, String> params = new HashMap<ConnectionConstants, String>();
+ params.put(ConnectionConstants.ADDRESS, addressStr);
+ params.put(ConnectionConstants.PORT, portStr);
+ 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 or passive");
+ return null;
+ }
+
public OvsdbClient getTestConnection() throws IOException, InterruptedException, ExecutionException, TimeoutException {
Properties props = loadProperties();
String addressStr = props.getProperty(SERVER_IPADDRESS);