fix for BUG-947 - ErrorHandler classLoader issue
[openflowplugin.git] / openflowplugin / src / test / java / org / opendaylight / openflowplugin / openflow / md / core / ConnectionConductorImplTest.java
index 03b30abaa9b2d36211241c14ca656ed3e2e064bf..73d5740a26e99f42a8d3dae1027f7508081a1559 100644 (file)
@@ -22,6 +22,13 @@ import org.junit.After;
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.ArgumentCaptor;
+import org.mockito.Matchers;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.runners.MockitoJUnitRunner;
+import org.opendaylight.openflowplugin.openflow.md.OFConstants;
 import org.opendaylight.openflowplugin.openflow.md.core.plan.ConnectionAdapterStackImpl;
 import org.opendaylight.openflowplugin.openflow.md.core.plan.EventFactory;
 import org.opendaylight.openflowplugin.openflow.md.core.plan.SwitchTestEvent;
@@ -30,8 +37,8 @@ import org.opendaylight.openflowplugin.openflow.md.queue.PopListener;
 import org.opendaylight.openflowplugin.openflow.md.queue.QueueKeeperLightImpl;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.Capabilities;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ErrorType;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.HelloElementType;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortFeatures;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortFeaturesV10;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortReason;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoRequestMessageBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ErrorMessage;
@@ -48,17 +55,11 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketInMessageBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortStatusMessage;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortStatusMessageBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.hello.Elements;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.hello.ElementsBuilder;
 import org.opendaylight.yangtools.yang.binding.DataObject;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import com.google.common.collect.Lists;
-
-/**
- * @author mirehak
- */
+@RunWith(MockitoJUnitRunner.class)
 public class ConnectionConductorImplTest {
 
     protected static final Logger LOG = LoggerFactory
@@ -88,7 +89,10 @@ public class ConnectionConductorImplTest {
     private int portstatusModifyMessageCounter;
     private int errorMessageCounter;
 
-    private ErrorHandlerQueueImpl errorHandler;
+    @Mock
+    private ErrorHandlerSimpleImpl errorHandler;
+
+    private int expectedErrors = 0;
 
     public void incrExperimenterMessageCounter() {
         this.experimenterMessageCounter++;
@@ -129,13 +133,10 @@ public class ConnectionConductorImplTest {
         popListener = new PopListenerCountingImpl<>();
 
         queueKeeper = new QueueKeeperLightImpl();
-        queueKeeper.init();
 
         connectionConductor = new ConnectionConductorImpl(adapter);
         connectionConductor.setQueueKeeper(queueKeeper);
         connectionConductor.init();
-        errorHandler = new ErrorHandlerQueueImpl();
-        pool.execute(errorHandler);
         connectionConductor.setErrorHandler(errorHandler);
         controller = new MDController();
         controller.init();
@@ -147,6 +148,7 @@ public class ConnectionConductorImplTest {
 
         controller.getMessageTranslators().putAll(assembleTranslatorMapping());
         queueKeeper.setPopListenersMapping(assemblePopListenerMapping());
+        queueKeeper.init();
     }
 
     /**
@@ -189,7 +191,17 @@ public class ConnectionConductorImplTest {
         Assert.assertTrue("plan is not finished", eventPlan.isEmpty());
         eventPlan = null;
         controller = null;
-        errorHandler = null;
+        
+        // logging errors if occurred
+        ArgumentCaptor<Throwable> errorCaptor = ArgumentCaptor.forClass(Throwable.class);
+        Mockito.verify(errorHandler, Mockito.atMost(1)).handleException(
+                errorCaptor.capture(), Matchers.any(SessionContext.class));
+        for (Throwable problem : errorCaptor.getAllValues()) {
+            LOG.warn(problem.getMessage(), problem);
+        }
+        
+        Mockito.verify(errorHandler, Mockito.times(expectedErrors )).handleException(
+                Matchers.any(Throwable.class), Matchers.any(SessionContext.class));
     }
 
     /**
@@ -200,6 +212,8 @@ public class ConnectionConductorImplTest {
      */
     @Test
     public void testOnEchoRequestMessage() throws Exception {
+        simulateV13PostHandshakeState(connectionConductor);
+        
         eventPlan.add(0, EventFactory.createDefaultNotificationEvent(42L,
                 EventFactory.DEFAULT_VERSION, new EchoRequestMessageBuilder()));
         eventPlan.add(0,
@@ -208,19 +222,51 @@ public class ConnectionConductorImplTest {
     }
 
     /**
-     * Test of handshake, covering version negotiation and features .
+     * Test of handshake, covering version negotiation and features.
+     * Switch delivers first helloMessage with default version.
      * @throws Exception
      */
     @Test
     public void testHandshake1() throws Exception {
-        eventPlan.add(0, EventFactory.createConnectionReadyCallback(connectionConductor));
         eventPlan.add(0, EventFactory.createDefaultNotificationEvent(42L,
                 EventFactory.DEFAULT_VERSION, new HelloMessageBuilder()));
         eventPlan.add(0, EventFactory.createDefaultWaitForAllEvent(
-                EventFactory.createDefaultWaitForRpcEvent(21, "helloReply"),
-                EventFactory.createDefaultWaitForRpcEvent(43, "getFeatures")));
+                EventFactory.createDefaultWaitForRpcEvent(43, "helloReply"),
+                EventFactory.createDefaultWaitForRpcEvent(44, "getFeatures")));
+        eventPlan.add(0, EventFactory.createDefaultRpcResponseEvent(44,
+                EventFactory.DEFAULT_VERSION, getFeatureResponseMsg()));
+        
+        eventPlan.add(0, EventFactory.createDefaultWaitForRpcEvent(1, "multipartRequestInput"));
+        eventPlan.add(0, EventFactory.createDefaultWaitForRpcEvent(2, "multipartRequestInput"));
+        eventPlan.add(0, EventFactory.createDefaultWaitForRpcEvent(3, "multipartRequestInput"));
+        eventPlan.add(0, EventFactory.createDefaultWaitForRpcEvent(4, "multipartRequestInput"));
+        executeNow();
+
+        Assert.assertEquals(ConnectionConductor.CONDUCTOR_STATE.WORKING,
+                connectionConductor.getConductorState());
+        Assert.assertEquals((short) 0x04, connectionConductor.getVersion()
+                .shortValue());
+    }
+    
+    /**
+     * Test of handshake, covering version negotiation and features.
+     * Controller sends first helloMessage with default version 
+     * @throws Exception
+     */
+    @Test
+    public void testHandshake1SwitchStarts() throws Exception {
+        eventPlan.add(0, EventFactory.createConnectionReadyCallback(connectionConductor));
+        eventPlan.add(0, EventFactory.createDefaultWaitForRpcEvent(21, "helloReply"));
+        eventPlan.add(0, EventFactory.createDefaultNotificationEvent(42L,
+                EventFactory.DEFAULT_VERSION, new HelloMessageBuilder()));
+        eventPlan.add(0, EventFactory.createDefaultWaitForRpcEvent(43, "getFeatures"));
         eventPlan.add(0, EventFactory.createDefaultRpcResponseEvent(43,
                 EventFactory.DEFAULT_VERSION, getFeatureResponseMsg()));
+        
+        eventPlan.add(0, EventFactory.createDefaultWaitForRpcEvent(1, "multipartRequestInput"));
+        eventPlan.add(0, EventFactory.createDefaultWaitForRpcEvent(2, "multipartRequestInput"));
+        eventPlan.add(0, EventFactory.createDefaultWaitForRpcEvent(3, "multipartRequestInput"));
+        eventPlan.add(0, EventFactory.createDefaultWaitForRpcEvent(4, "multipartRequestInput"));
 
         executeNow();
 
@@ -231,17 +277,18 @@ public class ConnectionConductorImplTest {
     }
 
     /**
-     * Test of handshake, covering version negotiation and features .
+     * Test of handshake, covering version negotiation and features.
+     * Switch delivers first helloMessage with version 0x05 
+     * and negotiates following versions: 0x03, 0x01 
      * @throws Exception
      */
     @Test
     public void testHandshake2() throws Exception {
         connectionConductor.setBitmapNegotiationEnable(false);
-        eventPlan.add(0, EventFactory.createConnectionReadyCallback(connectionConductor));
         eventPlan.add(0, EventFactory.createDefaultNotificationEvent(42L,
                 (short) 0x05, new HelloMessageBuilder()));
         eventPlan.add(0,
-                EventFactory.createDefaultWaitForRpcEvent(21, "helloReply"));
+                EventFactory.createDefaultWaitForRpcEvent(43, "helloReply"));
         eventPlan.add(0, EventFactory.createDefaultNotificationEvent(43L,
                 (short) 0x03, new HelloMessageBuilder()));
         eventPlan.add(0,
@@ -253,6 +300,9 @@ public class ConnectionConductorImplTest {
 
         eventPlan.add(0, EventFactory.createDefaultRpcResponseEvent(45,
                 EventFactory.DEFAULT_VERSION, getFeatureResponseMsg()));
+        
+        eventPlan.add(0, EventFactory.createDefaultWaitForRpcEvent(1, "multipartRequestInput"));
+        eventPlan.add(0, EventFactory.createDefaultWaitForRpcEvent(2, "multipartRequestInput"));
 
         executeNow();
 
@@ -261,20 +311,42 @@ public class ConnectionConductorImplTest {
         Assert.assertEquals((short) 0x01, connectionConductor.getVersion()
                 .shortValue());
     }
-
+    
     /**
-     * Test of handshake, covering version negotiation and features .
+     * Test of handshake, covering version negotiation and features.
+     * Controller sends first helloMessage with default version 
+     * and switch negotiates following versions: 0x05, 0x03, 0x01 
      * @throws Exception
      */
     @Test
-    public void testHandshake3() throws Exception {
+    public void testHandshake2SwitchStarts() throws Exception {
+        connectionConductor.setBitmapNegotiationEnable(false);
+        eventPlan.add(0, EventFactory.createConnectionReadyCallback(connectionConductor));
+        eventPlan.add(0,
+                EventFactory.createDefaultWaitForRpcEvent(21, "helloReply"));
         eventPlan.add(0, EventFactory.createDefaultNotificationEvent(42L,
-                (short) 0x00, new HelloMessageBuilder()));
+                (short) 0x05, new HelloMessageBuilder()));
+        eventPlan.add(0, EventFactory.createDefaultNotificationEvent(43L,
+                (short) 0x03, new HelloMessageBuilder()));
+        eventPlan.add(0,
+                EventFactory.createDefaultWaitForRpcEvent(44, "helloReply"));
+        eventPlan.add(0, EventFactory.createDefaultNotificationEvent(44L,
+                (short) 0x01, new HelloMessageBuilder()));
+        eventPlan.add(0,
+                EventFactory.createDefaultWaitForRpcEvent(45, "getFeatures"));
+
+        eventPlan.add(0, EventFactory.createDefaultRpcResponseEvent(45,
+                EventFactory.DEFAULT_VERSION, getFeatureResponseMsg()));
+        
+        eventPlan.add(0, EventFactory.createDefaultWaitForRpcEvent(1, "multipartRequestInput"));
+        eventPlan.add(0, EventFactory.createDefaultWaitForRpcEvent(2, "multipartRequestInput"));
 
         executeNow();
-        Assert.assertEquals(ConnectionConductor.CONDUCTOR_STATE.HANDSHAKING,
+
+        Assert.assertEquals(ConnectionConductor.CONDUCTOR_STATE.WORKING,
                 connectionConductor.getConductorState());
-        Assert.assertNull(connectionConductor.getVersion());
+        Assert.assertEquals((short) 0x01, connectionConductor.getVersion()
+                .shortValue());
     }
 
     /**
@@ -285,6 +357,8 @@ public class ConnectionConductorImplTest {
      */
     @Test
     public void testOnExperimenterMessage1() throws InterruptedException {
+        simulateV13PostHandshakeState(connectionConductor);
+        
         eventPlan.add(0,
                 EventFactory.createDefaultWaitForRpcEvent(42, "experimenter"));
         ExperimenterMessageBuilder builder1 = new ExperimenterMessageBuilder();
@@ -316,6 +390,8 @@ public class ConnectionConductorImplTest {
      */
     @Test
     public void testOnExperimenterMessage2() throws InterruptedException {
+        simulateV13PostHandshakeState(connectionConductor);
+        
         eventPlan.add(0,
                 EventFactory.createDefaultWaitForRpcEvent(42, "experimenter"));
         ErrorMessageBuilder builder1 = new ErrorMessageBuilder();
@@ -352,16 +428,7 @@ public class ConnectionConductorImplTest {
         IMDMessageTranslator<OfHeader, List<DataObject>> objFms = new FlowRemovedMessageService() ;
         controller.addMessageTranslator(FlowRemovedMessage.class, 4, objFms);
 
-        // Complete HandShake
-        eventPlan.add(0, EventFactory.createConnectionReadyCallback(connectionConductor));
-        eventPlan.add(0, EventFactory.createDefaultNotificationEvent(42L,
-                EventFactory.DEFAULT_VERSION, new HelloMessageBuilder()));
-        eventPlan.add(0, EventFactory.createDefaultWaitForAllEvent(
-                EventFactory.createDefaultWaitForRpcEvent(21, "helloReply"),
-                EventFactory.createDefaultWaitForRpcEvent(43, "getFeatures")));
-        eventPlan.add(0, EventFactory.createDefaultRpcResponseEvent(43,
-          EventFactory.DEFAULT_VERSION, getFeatureResponseMsg()));
-        execute(true);
+        simulateV13PostHandshakeState(connectionConductor);
 
         // Now send Flow Removed messages
         FlowRemovedMessageBuilder builder1 = new FlowRemovedMessageBuilder();
@@ -392,17 +459,6 @@ public class ConnectionConductorImplTest {
         // TODO:: add test
     }
 
-    /**
-     * Test method for
-     * {@link org.opendaylight.openflowplugin.openflow.md.core.ConnectionConductorImpl#onMultipartRequestMessage(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequestMessage)}
-     * .
-     */
-    @Test
-    public void testOnMultipartRequestMessage() {
-        // fail("Not yet implemented");
-        // TODO:: add test
-    }
-
     /**
      * Test method for
      * {@link org.opendaylight.openflowplugin.openflow.md.core.ConnectionConductorImpl#onPacketInMessage(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketInMessage)}
@@ -414,16 +470,7 @@ public class ConnectionConductorImplTest {
         IMDMessageTranslator<OfHeader, List<DataObject>> objPms = new PacketInMessageService() ;
         controller.addMessageTranslator(PacketInMessage.class, 4, objPms);
 
-        // Complete HandShake
-        eventPlan.add(0, EventFactory.createConnectionReadyCallback(connectionConductor));
-        eventPlan.add(0, EventFactory.createDefaultNotificationEvent(42L,
-        EventFactory.DEFAULT_VERSION, new HelloMessageBuilder()));
-        eventPlan.add(0, EventFactory.createDefaultWaitForAllEvent(
-                EventFactory.createDefaultWaitForRpcEvent(21, "helloReply"),
-                EventFactory.createDefaultWaitForRpcEvent(43, "getFeatures")));
-        eventPlan.add(0, EventFactory.createDefaultRpcResponseEvent(43,
-          EventFactory.DEFAULT_VERSION, getFeatureResponseMsg()));
-        execute(true);
+        simulateV13PostHandshakeState(connectionConductor);
 
         // Now send PacketIn
         PacketInMessageBuilder builder1 = new PacketInMessageBuilder();
@@ -450,20 +497,10 @@ public class ConnectionConductorImplTest {
      */
     @Test
     public void testOnPortStatusMessage() throws InterruptedException {
-
         IMDMessageTranslator<OfHeader, List<DataObject>> objPSms = new PortStatusMessageService() ;
         controller.addMessageTranslator(PortStatusMessage.class, 4, objPSms);
 
-        // Complete HandShake
-        eventPlan.add(0, EventFactory.createConnectionReadyCallback(connectionConductor));
-        eventPlan.add(0, EventFactory.createDefaultNotificationEvent(42L,
-        EventFactory.DEFAULT_VERSION, new HelloMessageBuilder()));
-        eventPlan.add(0, EventFactory.createDefaultWaitForAllEvent(
-                EventFactory.createDefaultWaitForRpcEvent(21, "helloReply"),
-                EventFactory.createDefaultWaitForRpcEvent(43, "getFeatures")));
-        eventPlan.add(0, EventFactory.createDefaultRpcResponseEvent(43,
-          EventFactory.DEFAULT_VERSION, getFeatureResponseMsg()));
-        execute(true);
+        simulateV13PostHandshakeState(connectionConductor);
 
         // Send Port Status messages
         PortStatusMessageBuilder builder1 = new PortStatusMessageBuilder();
@@ -515,233 +552,7 @@ public class ConnectionConductorImplTest {
         }
     }
 
-    //////// Start - Version Negotiation Test //////////////
-
-    /**
-     * Test of version negotiation Where switch version = 1.0
-     *
-     * @throws Exception
-     */
-    @Test
-    public void testVersionNegotiation10() throws Exception {
-        LOG.debug("testVersionNegotiation10");
-        Short version = (short) 0x01;
-        eventPlan.add(0, EventFactory.createConnectionReadyCallback(connectionConductor));
-        eventPlan.add(0, EventFactory.createDefaultNotificationEvent(42, version, new HelloMessageBuilder()));
-        eventPlan.add(0, EventFactory.createDefaultWaitForAllEvent(
-                EventFactory.createDefaultWaitForRpcEvent(21, "helloReply"),
-                EventFactory.createDefaultWaitForRpcEvent(43, "helloReply")));
-        eventPlan.add(0, EventFactory.createDefaultWaitForRpcEvent(44, "getFeatures"));
-        eventPlan.add(0,
-                EventFactory.createDefaultRpcResponseEvent(44, EventFactory.DEFAULT_VERSION, getFeatureResponseMsg()));
-
-        executeNow();
-        Assert.assertEquals(version, connectionConductor.getVersion());
-    }
-
-    /**
-     * Test of version negotiation Where switch version < 1.0
-     *
-     * @throws Exception
-     */
-    @Test
-    public void testVersionNegotiation00() throws Exception {
-        Short version = (short) 0x00;
-        eventPlan.add(0, EventFactory.createDefaultNotificationEvent(42L, version, new HelloMessageBuilder()));
-        executeNow();
-        Assert.assertNull(connectionConductor.getVersion());
-    }
-
-    /**
-     * Test of version negotiation Where 1.0 < switch version < 1.3
-     *
-     * @throws Exception
-     */
-    @Test
-    public void testVersionNegotiation11() throws Exception {
-        LOG.debug("testVersionNegotiation11");
-        connectionConductor.setBitmapNegotiationEnable(false);
-        Short version = (short) 0x02;
-        Short expVersion = (short) 0x01;
-        Assert.assertNull(connectionConductor.getVersion());
-
-        eventPlan.add(0, EventFactory.createConnectionReadyCallback(connectionConductor));
-        eventPlan.add(0, EventFactory.createDefaultNotificationEvent(42L, version, new HelloMessageBuilder()));
-        eventPlan.add(0, EventFactory.createDefaultWaitForAllEvent(
-                EventFactory.createDefaultWaitForRpcEvent(21, "helloReply"),
-                EventFactory.createDefaultWaitForRpcEvent(43, "helloReply")));
-        eventPlan.add(0, EventFactory.createDefaultNotificationEvent(44, expVersion, new HelloMessageBuilder()));
-        eventPlan.add(0, EventFactory.createDefaultWaitForRpcEvent(45, "getFeatures"));
-        eventPlan.add(0,
-                EventFactory.createDefaultRpcResponseEvent(45, EventFactory.DEFAULT_VERSION, getFeatureResponseMsg()));
-        executeNow();
-        Assert.assertEquals(expVersion, connectionConductor.getVersion());
-
-    }
-
-    /**
-     * Test of version negotiation Where switch version = 1.3
-     *
-     * @throws Exception
-     */
-    @Test
-    public void testVersionNegotiation13() throws Exception {
-        LOG.debug("testVersionNegotiation13");
-        Short version = (short) 0x04;
-        eventPlan.add(0, EventFactory.createConnectionReadyCallback(connectionConductor));
-        eventPlan.add(0, EventFactory.createDefaultNotificationEvent(42L, version, new HelloMessageBuilder()));
-        eventPlan.add(0, EventFactory.createDefaultWaitForAllEvent(
-                EventFactory.createDefaultWaitForRpcEvent(21, "helloReply"),
-                EventFactory.createDefaultWaitForRpcEvent(43, "getFeatures")));
-        eventPlan.add(0,
-                EventFactory.createDefaultRpcResponseEvent(43, EventFactory.DEFAULT_VERSION, getFeatureResponseMsg()));
-
-        executeNow();
-        Assert.assertEquals(version, connectionConductor.getVersion());
-    }
-
-    /**
-     * Test of version negotiation Where switch version >= 1.3
-     *
-     * @throws Exception
-     */
-    @Test
-    public void testVersionNegotiation15() throws Exception {
-        LOG.debug("testVersionNegotiation15");
-        connectionConductor.setBitmapNegotiationEnable(false);
-        Short version = (short) 0x06;
-        Short expVersion = (short) 0x04;
-        Assert.assertNull(connectionConductor.getVersion());
-
-        eventPlan.add(0, EventFactory.createConnectionReadyCallback(connectionConductor));
-        eventPlan.add(0, EventFactory.createDefaultNotificationEvent(42L, version, new HelloMessageBuilder()));
-        eventPlan.add(0, EventFactory.createDefaultWaitForRpcEvent(21, "helloReply"));
-        eventPlan.add(0, EventFactory.createDefaultNotificationEvent(44, expVersion, new HelloMessageBuilder()));
-        eventPlan.add(0, EventFactory.createDefaultWaitForRpcEvent(45, "getFeatures"));
-        eventPlan.add(0,
-                EventFactory.createDefaultRpcResponseEvent(45, EventFactory.DEFAULT_VERSION, getFeatureResponseMsg()));
-        executeNow();
-        Assert.assertEquals(expVersion, connectionConductor.getVersion());
-    }
-
-    /**
-     * Test of version negotiation Where switch version > 1.3
-     *
-     * @throws Exception
-     */
-    @Test
-    public void testVersionNegotiation15_MultipleCall() throws Exception {
-        LOG.debug("testVersionNegotiation15_MultipleCall");
-        connectionConductor.setBitmapNegotiationEnable(false);
-        Short version = (short) 0x06;
-        Assert.assertNull(connectionConductor.getVersion());
-
-        eventPlan.add(0, EventFactory.createConnectionReadyCallback(connectionConductor));
-        eventPlan.add(0, EventFactory.createDefaultWaitForRpcEvent(21, "helloReply"));
-        eventPlan.add(0, EventFactory.createDefaultNotificationEvent(42, version, new HelloMessageBuilder()));
-        eventPlan.add(0, EventFactory.createDefaultNotificationEvent(44, version, new HelloMessageBuilder()));
-        executeNow();
-        // TODO : check for connection termination
-        Assert.assertNull(connectionConductor.getVersion());
-    }
-
-    /**
-     * Test of version negotiation Where bitmap version {0x05,0x01}
-     *
-     * @throws Exception
-     */
-    @Test
-    public void testVersionNegotiation10InBitmap() throws Exception {
-        LOG.debug("testVersionNegotiation10InBitmap");
-        Short version = (short) 0x01;
-
-        eventPlan.add(0, EventFactory.createConnectionReadyCallback(connectionConductor));
-        eventPlan.add(
-                0,
-                EventFactory.createDefaultNotificationEvent(42L, (short) 0x05,
-                        getHelloBitmapMessage(Lists.newArrayList((short) 0x05, (short) 0x01))));
-        eventPlan.add(0, EventFactory.createDefaultWaitForAllEvent(
-                EventFactory.createDefaultWaitForRpcEvent(21, "helloReply"),
-                EventFactory.createDefaultWaitForRpcEvent(43, "getFeatures")));
-        eventPlan.add(0,
-                EventFactory.createDefaultRpcResponseEvent(43, EventFactory.DEFAULT_VERSION, getFeatureResponseMsg()));
-
-        executeNow();
-        Assert.assertEquals(version, connectionConductor.getVersion());
-    }
-
-    /**
-     * Test of version negotiation Where bitmap version {0x05,0x04}
-     *
-     * @throws Exception
-     */
-    @Test
-    public void testVersionNegotiation13InBitmap() throws Exception {
-        LOG.debug("testVersionNegotiation13InBitmap");
-        Short version = (short) 0x04;
-
-        eventPlan.add(0, EventFactory.createConnectionReadyCallback(connectionConductor));
-        eventPlan.add(
-                0,
-                EventFactory.createDefaultNotificationEvent(42L, (short) 0x05,
-                        getHelloBitmapMessage(Lists.newArrayList((short) 0x05, (short) 0x04))));
-        eventPlan.add(0, EventFactory.createDefaultWaitForAllEvent(
-                EventFactory.createDefaultWaitForRpcEvent(21, "helloReply"),
-                EventFactory.createDefaultWaitForRpcEvent(43, "getFeatures")));
-        eventPlan.add(0,
-                EventFactory.createDefaultRpcResponseEvent(43, EventFactory.DEFAULT_VERSION, getFeatureResponseMsg()));
-
-        executeNow();
-        Assert.assertEquals(version, connectionConductor.getVersion());
-    }
-
-    /**
-     * Test of version negotiation Where bitmap version {0x05,0x02}
-     *
-     * @throws Exception
-     */
-    @Test
-    public void testVersionNegotiationNoCommonVersionInBitmap() throws Exception {
-        eventPlan.add(
-                0,
-                EventFactory.createDefaultNotificationEvent(42L, (short) 0x05,
-                        getHelloBitmapMessage(Lists.newArrayList((short) 0x05, (short) 0x02))));
-        executeNow();
-        Assert.assertNull(connectionConductor.getVersion());
-    }
-
-    private HelloMessageBuilder getHelloBitmapMessage(List<Short> versionOrder) {
-        short highestVersion = versionOrder.get(0);
-        int elementsCount = highestVersion / Integer.SIZE;
-        ElementsBuilder elementsBuilder = new ElementsBuilder();
-
-        List<Elements> elementList = new ArrayList<>();
-        int orderIndex = versionOrder.size();
-        int value = versionOrder.get(--orderIndex);
-        for (int index = 0; index <= elementsCount; index++) {
-            List<Boolean> booleanList = new ArrayList<>();
-            for (int i = 0; i < Integer.SIZE; i++) {
-                if (value == ((index * Integer.SIZE) + i)) {
-                    booleanList.add(true);
-                    value = (orderIndex == 0) ? highestVersion : versionOrder.get(--orderIndex);
-                } else {
-                    booleanList.add(false);
-                }
-            }
-            elementsBuilder.setType(HelloElementType.forValue(1));
-            elementsBuilder.setVersionBitmap(booleanList);
-            elementList.add(elementsBuilder.build());
-        }
-
-        HelloMessageBuilder builder = new HelloMessageBuilder();
-        builder.setXid(10L);
-        builder.setVersion(highestVersion);
-        builder.setElements(elementList);
-        return builder;
-
-    }
-
-    private GetFeaturesOutputBuilder getFeatureResponseMsg() {
+    private static GetFeaturesOutputBuilder getFeatureResponseMsg() {
         GetFeaturesOutputBuilder getFeaturesOutputBuilder = new GetFeaturesOutputBuilder();
         getFeaturesOutputBuilder.setDatapathId(new BigInteger("102030405060"));
         getFeaturesOutputBuilder.setAuxiliaryId((short) 0);
@@ -828,6 +639,8 @@ public class ConnectionConductorImplTest {
      */
     @Test
     public void testOnExperimenterMessage() throws InterruptedException {
+        simulateV13PostHandshakeState(connectionConductor);
+        
         ExperimenterMessageBuilder builder1 = new ExperimenterMessageBuilder();
         builder1.setVersion((short) 4);
         builder1.setExperimenter(84L).setExpType(4L);
@@ -853,6 +666,8 @@ public class ConnectionConductorImplTest {
      */
     @Test
     public void testOnErrorMessage() throws InterruptedException {
+        simulateV13PostHandshakeState(connectionConductor);
+        
         ErrorMessageBuilder builder1 = new ErrorMessageBuilder();
         builder1.setVersion((short) 4);
         builder1.setCode(100);
@@ -892,4 +707,69 @@ public class ConnectionConductorImplTest {
         return translatorMapping;
     }
 
+    /**
+     * Test method for
+     * {@link org.opendaylight.openflowplugin.openflow.md.core.ConnectionConductorImpl#processPortStatusMsg(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortStatusMessage)}
+     * <br><br> 
+     * Tests for getting features from port status message by port version 
+     * <ul>
+     * <li>features are malformed - one of them is null</li>
+     * <li>mismatch between port version and port features</li>
+     * <li>mismatch between port version and port features</li>
+     * <li>non-existing port version</li>
+     * <li>port version OF 1.0</li>
+     * <li>port version OF 1.3</li>
+     * </ul>
+     * 
+     */
+    @Test
+    public void testProcessPortStatusMsg() {
+        simulateV13PostHandshakeState(connectionConductor);
+        
+               long portNumber = 90L;
+               long portNumberV10 = 91L;
+               PortStatusMessage msg;
+               
+               PortStatusMessageBuilder builder = new PortStatusMessageBuilder();              
+        PortFeatures features = new PortFeatures(true,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false);
+        PortFeatures featuresMal = new PortFeatures(true,false,false,false,null,false,false,false,false,false,false,false,false,false,false,false);
+        PortFeaturesV10 featuresV10 = new PortFeaturesV10(true,false,false,false,false,false,false,false,false,false,false,false);
+        
+        //Malformed features           
+        builder.setVersion((short) 1).setPortNo(portNumber).setReason(PortReason.OFPPRADD).setCurrentFeatures(featuresMal);            
+        connectionConductor.processPortStatusMsg(builder.build());
+               Assert.assertTrue(connectionConductor.getSessionContext().getPortsBandwidth().isEmpty());
+               Assert.assertTrue(connectionConductor.getSessionContext().getPhysicalPorts().isEmpty());
+               
+        //Version-features mismatch            
+        builder.setCurrentFeatures(features);          
+        connectionConductor.processPortStatusMsg(builder.build());
+               Assert.assertTrue(connectionConductor.getSessionContext().getPortsBandwidth().isEmpty());
+               Assert.assertTrue(connectionConductor.getSessionContext().getPhysicalPorts().isEmpty());
+               
+        //Non existing version
+        builder.setVersion((short) 0);
+        connectionConductor.processPortStatusMsg(builder.build());
+               Assert.assertTrue(connectionConductor.getSessionContext().getPortsBandwidth().isEmpty());
+               Assert.assertTrue(connectionConductor.getSessionContext().getPhysicalPorts().isEmpty());
+               
+               //Version OF 1.3
+               builder.setVersion((short) 4);
+               msg = builder.build();
+               connectionConductor.processPortStatusMsg(builder.build());
+               Assert.assertTrue(connectionConductor.getSessionContext().getPortBandwidth(portNumber));
+               Assert.assertEquals(connectionConductor.getSessionContext().getPhysicalPort(portNumber), msg);
+               
+               //Version OF 1.0                        
+               builder.setVersion((short) 1).setPortNo(portNumberV10).setCurrentFeatures(null).setCurrentFeaturesV10(featuresV10);
+               msg = builder.build();
+               connectionConductor.processPortStatusMsg(builder.build());
+               Assert.assertTrue(connectionConductor.getSessionContext().getPortBandwidth(portNumberV10));
+               Assert.assertEquals(connectionConductor.getSessionContext().getPhysicalPort(portNumberV10), msg);
+    }
+    
+    private void simulateV13PostHandshakeState(ConnectionConductorImpl conductor) {
+        GetFeaturesOutputBuilder featureOutput = getFeatureResponseMsg();
+        conductor.postHandshakeBasic(featureOutput.build(), OFConstants.OFP_VERSION_1_3);
+    }
 }