1 package org.opendaylight.ovsdb.integrationtest;
3 import static org.junit.Assert.assertNotNull;
4 import static org.junit.Assert.assertTrue;
5 import static org.junit.Assert.fail;
7 import java.io.IOException;
8 import java.util.HashMap;
11 import java.util.Properties;
12 import java.util.concurrent.ExecutionException;
13 import java.util.concurrent.TimeoutException;
14 import org.opendaylight.controller.sal.core.Node;
15 import org.opendaylight.controller.sal.utils.ServiceHelper;
16 import org.opendaylight.ovsdb.plugin.api.ConnectionConstants;
17 import org.opendaylight.ovsdb.compatibility.plugin.api.OvsdbConnectionService;
18 import org.slf4j.Logger;
19 import org.slf4j.LoggerFactory;
21 public abstract class CompatOvsdbIntegrationTestBase extends OvsdbIntegrationTestBase {
22 private static final Logger LOG = LoggerFactory.getLogger(OvsdbIntegrationTestBase.class);
24 public Node getCompatPluginTestConnection() throws IOException,
25 InterruptedException, ExecutionException, TimeoutException {
26 Properties props = loadProperties();
27 String addressStr = props.getProperty(SERVER_IPADDRESS);
28 String portStr = props.getProperty(SERVER_PORT, DEFAULT_SERVER_PORT);
29 String connectionType = props.getProperty(CONNECTION_TYPE, "active");
30 org.opendaylight.controller.sal.core.Node node = null;
32 OvsdbConnectionService connection = (OvsdbConnectionService)
33 ServiceHelper.getGlobalInstance(OvsdbConnectionService.class, this);
34 // If the connection type is active, controller connects to the ovsdb-server
35 if (connectionType.equalsIgnoreCase(CONNECTION_TYPE_ACTIVE)) {
36 if (addressStr == null) {
40 Map<ConnectionConstants, String> params = new HashMap<ConnectionConstants, String>();
41 params.put(ConnectionConstants.ADDRESS, addressStr);
42 params.put(ConnectionConstants.PORT, portStr);
43 node = connection.connect(IDENTIFIER, params);
44 } else if (connectionType.equalsIgnoreCase(CONNECTION_TYPE_PASSIVE)) {
45 // Wait for CONNECTION_INIT_TIMEOUT for the Passive connection to be initiated by the ovsdb-server.
46 Thread.sleep(CONNECTION_INIT_TIMEOUT);
47 List<Node> nodes = connection.getNodes();
49 assertTrue(nodes.size() > 0);
54 LOG.info("getPluginTestConnection: Successfully connected to {}", node);
56 fail("Connection parameter (" + CONNECTION_TYPE + ") must be active or passive");