fixed it-test (added bundles) 83/2383/2
authorMichal Rehak <mirehak@cisco.com>
Tue, 5 Nov 2013 12:37:27 +0000 (13:37 +0100)
committerMichal Rehak <mirehak@cisco.com>
Tue, 5 Nov 2013 13:32:26 +0000 (14:32 +0100)
ConnectionConductorImpl.onHelloMessage now delegates it's previous content to new thread

Change-Id: Ib88560515f80a01ab8ab70157df34adcecaaa915
Signed-off-by: Michal Rehak <mirehak@cisco.com>
openflowplugin-it/src/test/java/org/opendaylight/openflowplugin/openflow/md/it/SalIntegrationTest.java
openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/ConnectionConductorImpl.java
openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/plan/ConnectionAdapterStackImpl.java
openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/session/MessageDispatchServiceImplTest.java

index 631bb8f09a3c629959ddfa7c581020e560d623f8..27ed94cf042e16a2811bd6022ae438570d2a226a 100644 (file)
@@ -1,5 +1,12 @@
 package org.opendaylight.openflowplugin.openflow.md.it;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.opendaylight.controller.test.sal.binding.it.TestHelper.baseModelBundles;
+import static org.opendaylight.controller.test.sal.binding.it.TestHelper.bindingAwareSalBundles;
+import static org.opendaylight.controller.test.sal.binding.it.TestHelper.configMinumumBundles;
+import static org.opendaylight.controller.test.sal.binding.it.TestHelper.flowCapableModelBundles;
+import static org.opendaylight.controller.test.sal.binding.it.TestHelper.mdSalCoreBundles;
 import static org.ops4j.pax.exam.CoreOptions.junitBundles;
 import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
 import static org.ops4j.pax.exam.CoreOptions.options;
@@ -13,10 +20,9 @@ import javax.inject.Inject;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
+import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ConsumerContext;
 import org.opendaylight.controller.sal.binding.api.BindingAwareConsumer;
 import org.opendaylight.controller.sal.binding.api.NotificationService;
-import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ConsumerContext;
-import org.opendaylight.controller.test.sal.binding.it.TestHelper;
 import org.opendaylight.openflowjava.protocol.impl.clients.ScenarioFactory;
 import org.opendaylight.openflowjava.protocol.impl.clients.ScenarioHandler;
 import org.opendaylight.openflowjava.protocol.impl.clients.SimpleClient;
@@ -33,9 +39,6 @@ import org.osgi.framework.BundleContext;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import static org.junit.Assert.*;
-import static org.opendaylight.controller.test.sal.binding.it.TestHelper.*;
-
 /**
  * @author mirehak
  */
@@ -121,6 +124,7 @@ public class SalIntegrationTest {
                 mavenBundle(ODL, "sal").versionAsInProject(), mavenBundle(ODL, "sal.connection").versionAsInProject(),
 
                 mdSalCoreBundles(), bindingAwareSalBundles(), baseModelBundles(), flowCapableModelBundles(),
+                configMinumumBundles(),
 
                 mavenBundle("org.opendaylight.controller.thirdparty", "org.openflow.openflowj").versionAsInProject(),
 
@@ -143,6 +147,13 @@ public class SalIntegrationTest {
         List<NodeRemoved> nodeRemoved = new ArrayList<>();
         List<NodeConnectorUpdated> nodeConnectorUpdated = new ArrayList<>();
         List<NodeConnectorRemoved> nodeConnectorRemoved = new ArrayList<>();
+        
+        /**
+         * default ctor
+         */
+        protected TestInventoryListener() {
+            // do nothing
+        }
 
         @Override
         public void onNodeUpdated(NodeUpdated notification) {
@@ -163,6 +174,6 @@ public class SalIntegrationTest {
         public void onNodeConnectorRemoved(NodeConnectorRemoved notification) {
             nodeConnectorRemoved.add(notification);
         }
-    };
+    }
 
 }
index 266201878145bccb6a50a7133ee9fab8db1cc6d6..d6098b1c726ccaa442f581ff4b4ed9a4577caff5 100644 (file)
@@ -17,6 +17,7 @@ import java.util.concurrent.LinkedBlockingQueue;
 import java.util.concurrent.TimeUnit;
 
 import org.opendaylight.openflowjava.protocol.api.connection.ConnectionAdapter;
+import org.opendaylight.openflowjava.protocol.api.connection.ConnectionReadyListener;
 import org.opendaylight.openflowplugin.openflow.md.core.session.OFSessionUtil;
 import org.opendaylight.openflowplugin.openflow.md.core.session.SessionContext;
 import org.opendaylight.openflowplugin.openflow.md.core.session.SessionManager;
@@ -55,7 +56,7 @@ import com.google.common.util.concurrent.Futures;
  * @author mirehak
  */
 public class ConnectionConductorImpl implements OpenflowProtocolListener,
-        SystemNotificationsListener, ConnectionConductor {
+        SystemNotificationsListener, ConnectionConductor, ConnectionReadyListener {
 
     private static final Logger LOG = LoggerFactory
             .getLogger(ConnectionConductorImpl.class);
@@ -97,8 +98,7 @@ public class ConnectionConductorImpl implements OpenflowProtocolListener,
     public void init() {
         connectionAdapter.setMessageListener(this);
         connectionAdapter.setSystemListener(this);
-        //TODO : Wait for library to provide interface from which we can send first hello message
-//        sendFirstHelloMessage();
+        connectionAdapter.setConnectionReadyListener(this);
     }
 
 
@@ -184,57 +184,64 @@ public class ConnectionConductorImpl implements OpenflowProtocolListener,
      *   TODO: Better to handle handshake into a maintainable innerclass which uses State-Pattern.
      */
     @Override
-    public void onHelloMessage(HelloMessage hello) {
+    public void onHelloMessage(final HelloMessage hello) {
         // do handshake
         LOG.info("handshake STARTED");
         checkState(CONDUCTOR_STATE.HANDSHAKING);
 
-        Short remoteVersion = hello.getVersion();
-        List<Elements> elements = hello.getElements();
-        long xid = hello.getXid();
-        short proposedVersion;
-        LOG.debug("Hello message version={} and bitmap={}", remoteVersion, elements);
-        try {
-            // find the version from header version field
-            proposedVersion = proposeVersion(remoteVersion);
-
-        } catch (IllegalArgumentException e) {
-            handleException(e);
-            connectionAdapter.disconnect();
-            throw e;
-        }
-
-        // sent version is equal to remote --> version is negotiated
-        if (proposedVersion == remoteVersion) {
-            LOG.debug("sending helloReply as version in header is supported: {}", proposedVersion);
-            sendHelloReply(proposedVersion, ++xid);
-            postHandshake(proposedVersion, ++xid);
-
-        } else if (isBitmapNegotiationEnable && null != elements && 0 != elements.size()) {
-            try {
-                // hello contains version bitmap, checking highest common
-                // version in bitmap
-                proposedVersion = proposeBitmapVersion(elements);
-            } catch (IllegalArgumentException ex) {
-                handleException(ex);
-                connectionAdapter.disconnect();
-                throw ex;
-            }
-            LOG.debug("sending helloReply for common bitmap version : {}", proposedVersion);
-            sendHelloReply(proposedVersion, ++xid);
-            postHandshake(proposedVersion, ++xid);
-        } else {
-            if (isFirstHelloNegotiation) {
-                isFirstHelloNegotiation = false;
-                LOG.debug("sending helloReply for lowest supported version : {}", proposedVersion);
-                // send hello reply with lower version number supported
-                sendHelloReply(proposedVersion, ++xid);
-            } else {
-                // terminate the connection.
-                LOG.debug("Version negotiation failed. unsupported version : {}", remoteVersion);
-                connectionAdapter.disconnect();
+        new Thread(new Runnable() {
+
+            @Override
+            public void run() {
+                Short remoteVersion = hello.getVersion();
+                List<Elements> elements = hello.getElements();
+                long xid = hello.getXid();
+                short proposedVersion;
+                LOG.debug("Hello message version={} and bitmap={}", remoteVersion, elements);
+                try {
+                    // find the version from header version field
+                    proposedVersion = proposeVersion(remoteVersion);
+                    
+                } catch (IllegalArgumentException e) {
+                    handleException(e);
+                    connectionAdapter.disconnect();
+                    throw e;
+                }
+                
+                // sent version is equal to remote --> version is negotiated
+                if (proposedVersion == remoteVersion) {
+                    LOG.debug("sending helloReply as version in header is supported: {}", proposedVersion);
+                    sendHelloReply(proposedVersion, ++xid);
+                    postHandshake(proposedVersion, ++xid);
+                    
+                } else if (isBitmapNegotiationEnable && null != elements && 0 != elements.size()) {
+                    try {
+                        // hello contains version bitmap, checking highest common
+                        // version in bitmap
+                        proposedVersion = proposeBitmapVersion(elements);
+                    } catch (IllegalArgumentException ex) {
+                        handleException(ex);
+                        connectionAdapter.disconnect();
+                        throw ex;
+                    }
+                    LOG.debug("sending helloReply for common bitmap version : {}", proposedVersion);
+                    sendHelloReply(proposedVersion, ++xid);
+                    postHandshake(proposedVersion, ++xid);
+                } else {
+                    if (isFirstHelloNegotiation) {
+                        isFirstHelloNegotiation = false;
+                        LOG.debug("sending helloReply for lowest supported version : {}", proposedVersion);
+                        // send hello reply with lower version number supported
+                        sendHelloReply(proposedVersion, ++xid);
+                    } else {
+                        // terminate the connection.
+                        LOG.debug("Version negotiation failed. unsupported version : {}", remoteVersion);
+                        connectionAdapter.disconnect();
+                    }
+                }
             }
-        }
+            
+        }).start();
     }
 
     /**
@@ -535,4 +542,9 @@ public class ConnectionConductorImpl implements OpenflowProtocolListener,
     public ConnectionAdapter getConnectionAdapter() {
         return connectionAdapter;
     }
+
+    @Override
+    public void onConnectionReady() {
+        // TODO Auto-generated method stub
+    }
 }
index 490deea6d3f99a9a7da8ffff84efe2311ceb86c1..eb9d411a944ffa5b0b98b2d11d86ef51fd4de01e 100644 (file)
@@ -23,6 +23,7 @@ import java.util.concurrent.TimeUnit;
 import org.opendaylight.controller.sal.common.util.RpcErrors;
 import org.opendaylight.controller.sal.common.util.Rpcs;
 import org.opendaylight.openflowjava.protocol.api.connection.ConnectionAdapter;
+import org.opendaylight.openflowjava.protocol.api.connection.ConnectionReadyListener;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.BarrierInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.BarrierOutput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoInput;
@@ -96,6 +97,8 @@ public class ConnectionAdapterStackImpl implements ConnectionAdapter, Runnable {
 
     protected List<Exception> occuredExceptions = new ArrayList<>();
 
+    private ConnectionReadyListener connectionReadyListener;
+
     /**
      * default ctor
      */
@@ -269,7 +272,7 @@ public class ConnectionAdapterStackImpl implements ConnectionAdapter, Runnable {
 
     @Override
     public void checkListeners() {
-        if (ofListener == null || systemListener == null) {
+        if (ofListener == null || systemListener == null || connectionReadyListener == null) {
             occuredExceptions
                     .add(new IllegalStateException("missing listeners"));
         }
@@ -532,4 +535,17 @@ public class ConnectionAdapterStackImpl implements ConnectionAdapter, Runnable {
     public List<Exception> getOccuredExceptions() {
         return occuredExceptions;
     }
+
+    @Override
+    public void fireConnectionReadyNotification() {
+        if (connectionReadyListener != null) {
+            connectionReadyListener.onConnectionReady();
+        }
+    }
+
+    @Override
+    public void setConnectionReadyListener(
+            ConnectionReadyListener connectionReadyListener) {
+        this.connectionReadyListener = connectionReadyListener;
+    }
 }
index 88aab1cf1cb2cb47e4a8c2e621f81e2f9fb159a7..8195950fb5b8f0877d81b0ae46aeced372768f66 100644 (file)
@@ -14,6 +14,7 @@ import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 import org.opendaylight.openflowjava.protocol.api.connection.ConnectionAdapter;
+import org.opendaylight.openflowjava.protocol.api.connection.ConnectionReadyListener;
 import org.opendaylight.openflowplugin.openflow.md.core.ConnectionConductor;
 import org.opendaylight.openflowplugin.openflow.md.core.SwitchConnectionDistinguisher;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.BarrierInput;
@@ -372,6 +373,7 @@ enum MessageType {
 class MockConnectionAdapter implements ConnectionAdapter {
 
     private MessageType messageType;
+    private ConnectionReadyListener connectionReadyListener;
 
     public MockConnectionAdapter() {
         setMessageType(MessageType.NONE);
@@ -530,4 +532,17 @@ class MockConnectionAdapter implements ConnectionAdapter {
         this.messageType = messageType;
     }
 
+    @Override
+    public void fireConnectionReadyNotification() {
+        if (connectionReadyListener != null) {
+            connectionReadyListener.onConnectionReady();
+        }
+    }
+
+    @Override
+    public void setConnectionReadyListener(
+            ConnectionReadyListener connectionReadyListener) {
+        this.connectionReadyListener = connectionReadyListener;
+    }
+
 }