Northbound migration to use the new Schema independent Library based Plugin.
[ovsdb.git] / integrationtest / src / test / java / org / opendaylight / ovsdb / integrationtest / OvsdbIntegrationTestBase.java
index 76f7647916d65f538e3ca856b54971c80e16f9fd..9a921cf56b4125926a33f07e9eea3bb4d840c65d 100644 (file)
 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;
@@ -23,10 +28,13 @@ import java.util.concurrent.Future;
 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";
@@ -49,6 +57,35 @@ public abstract class OvsdbIntegrationTestBase {
         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);