Adding Passive connection support to plugin layer. 11/8611/1
authorMadhu Venugopal <mavenugo@gmail.com>
Sat, 28 Jun 2014 07:07:53 +0000 (00:07 -0700)
committerMadhu Venugopal <mavenugo@gmail.com>
Sat, 28 Jun 2014 07:07:53 +0000 (00:07 -0700)
Change-Id: Iaf8aed4d19e6ce45d6fce0e75389d4696fd86cc7
Signed-off-by: Madhu Venugopal <mavenugo@gmail.com>
integrationtest/src/test/java/org/opendaylight/ovsdb/integrationtest/plugin/OvsdbPluginIT.java
library/src/main/java/org/opendaylight/ovsdb/lib/schema/GenericTableSchema.java
plugin/src/main/java/org/opendaylight/ovsdb/plugin/Activator.java
plugin/src/main/java/org/opendaylight/ovsdb/plugin/ConnectionService.java

index 837882781276bb5ab3a3b828484458d896ebb201..5a0301fdbb91304ddb2e1d78f236c6f1791ca86a 100644 (file)
@@ -39,6 +39,8 @@ import org.opendaylight.controller.sal.utils.ServiceHelper;
 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;
@@ -102,6 +104,7 @@ public class OvsdbPluginIT extends OvsdbIntegrationTestBase {
         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) {
@@ -111,11 +114,16 @@ public class OvsdbPluginIT extends OvsdbIntegrationTestBase {
             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;
     }
 
@@ -148,14 +156,21 @@ public class OvsdbPluginIT extends OvsdbIntegrationTestBase {
     @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);
index d5f493df47feccbbaff36adb84bb4498d91aa87b..2851263a3fb353d35da661d338536375933ee407 100644 (file)
@@ -41,7 +41,7 @@ public class GenericTableSchema extends TableSchema<GenericTableSchema> {
         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()));
         }
 
index 65a2a48819da3dd964b2c3d24c21c65b0b1dcc8f..6c0773c5b8ca5bdfc0ea00f3dc29330ba9a50ac6 100644 (file)
@@ -25,7 +25,6 @@ import org.opendaylight.controller.sal.utils.GlobalConstants;
 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;
 
@@ -95,8 +94,8 @@ public class Activator extends ComponentActivatorAbstractBase {
             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")
index 55f8717047e89c61dc8eeaf418a27565be1a8839..c94b22b03f3e3a8c4d098a0fc8a379dfe14624d1 100644 (file)
@@ -90,6 +90,10 @@ public class ConnectionService implements IPluginInConnectionService, IConnectio
 
     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) {
@@ -170,7 +174,7 @@ public class ConnectionService implements IPluginInConnectionService, IConnectio
 
         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) {
@@ -210,7 +214,7 @@ public class ConnectionService implements IPluginInConnectionService, IConnectio
     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);
@@ -442,20 +446,19 @@ public class ConnectionService implements IPluginInConnectionService, IConnectio
         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());
     }
 }