2 * Copyright (C) 2014 Red Hat, Inc.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 * Authors : Madhu Venugopal
11 package org.opendaylight.ovsdb.schema.hardwarevtep;
13 import java.io.IOException;
14 import java.net.InetAddress;
15 import java.util.Properties;
16 import java.util.concurrent.Callable;
17 import java.util.concurrent.ExecutionException;
18 import java.util.concurrent.ExecutorService;
19 import java.util.concurrent.Executors;
20 import java.util.concurrent.Future;
21 import java.util.concurrent.TimeUnit;
22 import java.util.concurrent.TimeoutException;
24 import junit.framework.Assert;
26 import org.opendaylight.ovsdb.lib.OvsdbClient;
27 import org.opendaylight.ovsdb.lib.OvsdbConnection;
28 import org.opendaylight.ovsdb.lib.OvsdbConnectionListener;
29 import org.opendaylight.ovsdb.lib.impl.OvsdbConnectionService;
30 import org.opendaylight.ovsdb.lib.message.OvsdbRPC;
32 public abstract class OvsdbTestBase implements OvsdbRPC.Callback{
33 private final static String SERVER_IPADDRESS = "ovsdbserver.ipaddress";
34 private final static String SERVER_PORT = "ovsdbserver.port";
35 private final static String DEFAULT_SERVER_PORT = "6640";
36 private final static String CONNECTION_TYPE = "ovsdbserver.connection";
37 private final static String CONNECTION_TYPE_ACTIVE = "active";
38 private final static String CONNECTION_TYPE_PASSIVE = "passive";
41 * Represents the Hardware VTEP Schema
43 public final static String HARDWARE_VTEP_SCHEMA = "hardware_vtep";
45 public Properties loadProperties() {
46 Properties props = new Properties(System.getProperties());
51 public OvsdbClient getTestConnection() throws IOException, InterruptedException, ExecutionException, TimeoutException {
52 Properties props = loadProperties();
53 String addressStr = props.getProperty(SERVER_IPADDRESS);
54 String portStr = props.getProperty(SERVER_PORT, DEFAULT_SERVER_PORT);
55 String connectionType = props.getProperty(CONNECTION_TYPE, "active");
57 // If the connection type is active, controller connects to the ovsdb-server
58 if (connectionType.equalsIgnoreCase(CONNECTION_TYPE_ACTIVE)) {
59 if (addressStr == null) {
65 address = InetAddress.getByName(addressStr);
66 } catch (Exception e) {
67 System.out.println("Unable to resolve " + addressStr);
74 port = Integer.parseInt(portStr);
75 } catch (NumberFormatException e) {
76 System.out.println("Invalid port number : " + portStr);
81 OvsdbConnection connection = OvsdbConnectionService.getService();
82 return connection.connect(address, port);
83 } else if (connectionType.equalsIgnoreCase(CONNECTION_TYPE_PASSIVE)) {
84 ExecutorService executor = Executors.newFixedThreadPool(1);
85 Future<OvsdbClient> passiveConnection = executor.submit(new PassiveListener());
86 return passiveConnection.get(60, TimeUnit.SECONDS);
88 Assert.fail("Connection parameter ("+CONNECTION_TYPE+") must be either active or passive");
92 private String usage() {
93 return "Integration Test needs a valid connection configuration as follows :\n" +
94 "active connection : mvn -Pintegrationtest -Dovsdbserver.ipaddress=x.x.x.x -Dovsdbserver.port=yyyy verify\n"+
95 "passive connection : mvn -Pintegrationtest -Dovsdbserver.connection=passive verify\n";
98 public class PassiveListener implements Callable<OvsdbClient>, OvsdbConnectionListener {
99 OvsdbClient client = null;
101 public OvsdbClient call() throws Exception {
102 OvsdbConnection connection = OvsdbConnectionService.getService();
103 connection.registerForPassiveConnection(this);
104 while (client == null) {
111 public void connected(OvsdbClient client) {
112 this.client = client;
116 public void disconnected(OvsdbClient client) {
117 Assert.assertEquals(this.client.getConnectionInfo(), client.getConnectionInfo());