Merge "BUG-2706: Processing of messages from device starts too late"
authormichal rehak <mirehak@cisco.com>
Fri, 13 Feb 2015 16:53:45 +0000 (16:53 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Fri, 13 Feb 2015 16:53:45 +0000 (16:53 +0000)
applications/topology-lldp-discovery/pom.xml
legacy/sal-compatibility/src/main/java/org/opendaylight/openflowplugin/legacy/sal/compatibility/NodeConnectorDataChangeListener.java
openflowplugin-it/pom.xml
openflowplugin-it/src/test/java/org/opendaylight/openflowplugin/openflow/md/it/OFPluginToLibraryTest.java
openflowplugin-it/src/test/java/org/opendaylight/openflowplugin/openflow/md/it/SalIntegrationTest.java
openflowplugin-it/src/test/java/org/opendaylight/openflowplugin/openflow/md/it/SimulatorAssistant.java [new file with mode: 0644]
openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/match/MatchConvertorImpl.java
openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/match/MatchConvertorImplV13Test.java
pom.xml

index 1e6fe7eb8177bf1641efd60606c85ef8d2dc1870..c0a2202104cff232c78c95181e188bea5c610dd0 100644 (file)
   <artifactId>topology-lldp-discovery</artifactId>
   <packaging>bundle</packaging>
 
-  <properties>
-    <bundle.plugin.version>2.4.0</bundle.plugin.version>
-    <guava.version>14.0.1</guava.version>
-    <maven.clean.plugin.version>2.5</maven.clean.plugin.version>
-  </properties>
   <dependencies>
     <dependency>
       <groupId>com.google.guava</groupId>
index c186f36759dcb00dc6e773585b5ef95f96b76ae1..e291bc529c19d919a2afafacd83a018068440153 100644 (file)
@@ -59,7 +59,7 @@ public class NodeConnectorDataChangeListener implements DataChangeListener{
             try {
                 nodeConnector = NodeMapping.toADNodeConnector(nodeConnectorRef);
             } catch (ConstructionException e) {
-                e.printStackTrace();
+                LOG.debug("Construction exception: %s",e.getMessage());
             }
             HashSet<Property> _aDNodeConnectorProperties = NodeMapping.toADNodeConnectorProperties((org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector) entry.getValue());
             this.publishNodeConnectorUpdate(nodeConnector, updateType, _aDNodeConnectorProperties);
index 3e10e906f4394d9de925ad03cca7e790b9487796..d73764877daffa91c889116627a32e9de7369183 100644 (file)
           <artifactId>nagasena-rta</artifactId>
           <scope>test</scope>
         </dependency>
-        <dependency>
-          <groupId>org.opendaylight.controller.thirdparty</groupId>
-          <artifactId>ganymed</artifactId>
-          <scope>test</scope>
-        </dependency>
-            
+
         <dependency>
             <groupId>org.slf4j</groupId>
             <artifactId>log4j-over-slf4j</artifactId>
index 774cd1ae37352bc59ed74477f7f465b8a8f8ab36..1415ed2bb97bfd3a9beaa443e999e67ecc076715 100644 (file)
@@ -17,7 +17,6 @@ import java.util.concurrent.TimeUnit;
 import javax.inject.Inject;
 
 import org.junit.After;
-import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -48,7 +47,7 @@ public class OFPluginToLibraryTest {
     private static final Logger LOG = LoggerFactory
             .getLogger(OFPluginToLibraryTest.class);
 
-    private static final ArrayBlockingQueue<Runnable> SCENARIO_POOL_QUEUE = new ArrayBlockingQueue<>(1);
+    private final ArrayBlockingQueue<Runnable> SCENARIO_POOL_QUEUE = new ArrayBlockingQueue<>(1);
 
     @Inject @Filter(timeout=20000)
     OpenflowPluginProvider openflowPluginProvider;
@@ -66,9 +65,8 @@ public class OFPluginToLibraryTest {
     @Before
     public void setUp() throws InterruptedException {
         LOG.debug("openflowPluginProvider: "+openflowPluginProvider);
+        switchSim = createSimpleClient();
         scenarioPool = new ThreadPoolLoggingExecutor(1, 1, 0L, TimeUnit.MILLISECONDS, SCENARIO_POOL_QUEUE, "scenario");
-        //FIXME: plugin should provide service exposing startup result via future
-        Thread.sleep(5000);
     }
 
     /**
@@ -76,27 +74,8 @@ public class OFPluginToLibraryTest {
      */
     @After
     public void tearDown() {
-        try {
-            LOG.debug("tearing down simulator");
-            switchSim.getScenarioDone().get(getFailSafeTimeout(), TimeUnit.MILLISECONDS);
-        } catch (Exception e) {
-            String msg = "waiting for scenario to finish failed: "+e.getMessage();
-            LOG.error(msg, e);
-            Assert.fail(msg);
-        } finally {
-            scenarioPool.shutdownNow();
-            SCENARIO_POOL_QUEUE.clear();
-        }
-
-        try {
-            LOG.debug("checking if simulator succeeded to connect to controller");
-            boolean simulatorWasOnline = switchSim.getIsOnlineFuture().get(100, TimeUnit.MILLISECONDS);
-            Assert.assertTrue("simulator failed to connect to controller", simulatorWasOnline);
-        } catch (Exception e) {
-            String message = "simulator probably failed to connect to controller";
-            LOG.error(message, e);
-            Assert.fail(message);
-        }
+        SimulatorAssistant.waitForSwitchSimulatorOn(switchSim);
+        SimulatorAssistant.tearDownSwitchSimulatorAfterScenario(switchSim, scenarioPool, getFailSafeTimeout());
     }
 
     /**
@@ -107,7 +86,6 @@ public class OFPluginToLibraryTest {
     public void handshakeOk1() throws Exception {
         LOG.debug("handshakeOk1 integration test");
 
-        switchSim = createSimpleClient();
         switchSim.setSecuredClient(false);
         Deque<ClientEvent> handshakeScenario = ScenarioFactory.createHandshakeScenarioVBM(
                 ScenarioFactory.VERSION_BITMAP_13, (short) 0, ScenarioFactory.VERSION_BITMAP_10_13);
index 9091ca430bdb3382e0deb847ed5ae53bdf278795..07442c3cad97644d8c8e5a98f993d5d5c93f1db1 100644 (file)
@@ -14,11 +14,12 @@ import static org.ops4j.pax.exam.CoreOptions.systemProperty;
 
 import java.util.ArrayList;
 import java.util.List;
+import java.util.concurrent.ArrayBlockingQueue;
 import java.util.concurrent.TimeUnit;
 
 import javax.inject.Inject;
 
-import org.junit.Assert;
+import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -29,6 +30,7 @@ import org.opendaylight.controller.sal.binding.api.NotificationService;
 import org.opendaylight.controller.test.sal.binding.it.TestHelper;
 import org.opendaylight.openflowjava.protocol.impl.clients.ScenarioHandler;
 import org.opendaylight.openflowjava.protocol.impl.clients.SimpleClient;
+import org.opendaylight.openflowplugin.openflow.md.core.ThreadPoolLoggingExecutor;
 import org.opendaylight.openflowplugin.openflow.md.core.sal.OpenflowPluginProvider;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorRemoved;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorUpdated;
@@ -49,8 +51,13 @@ import org.slf4j.LoggerFactory;
 @RunWith(PaxExam.class)
 public class SalIntegrationTest {
 
-    private static final Logger LOG = LoggerFactory.getLogger(SalIntegrationTest.class);
+    static final Logger LOG = LoggerFactory.getLogger(SalIntegrationTest.class);
 
+    private final ArrayBlockingQueue<Runnable> SCENARIO_POOL_QUEUE = new ArrayBlockingQueue<>(1);
+    private ThreadPoolLoggingExecutor scenarioPool;
+    private SimpleClient switchSim;
+    private Runnable finalCheck;
+    
     @Inject
     BundleContext ctx;
 
@@ -64,7 +71,7 @@ public class SalIntegrationTest {
     /**
      * @return timeout for case of failure
      */
-    private static long getFailSafeTimeout() {
+    static long getFailSafeTimeout() {
         return 30000;
     }
     
@@ -74,10 +81,24 @@ public class SalIntegrationTest {
      */
     @Before
     public void setUp() throws InterruptedException {
-        //FIXME: plugin should provide service exposing startup result via future 
-        Thread.sleep(6000);
+        switchSim = new SimpleClient("localhost", 6653);
+        scenarioPool = new ThreadPoolLoggingExecutor(1, 1, 0L, TimeUnit.MILLISECONDS, SCENARIO_POOL_QUEUE, "scenario");
     }
-    
+
+    /**
+     * test tear down
+     */
+    @After
+    public void tearDown() {
+        SimulatorAssistant.waitForSwitchSimulatorOn(switchSim);
+        SimulatorAssistant.tearDownSwitchSimulatorAfterScenario(switchSim, scenarioPool, getFailSafeTimeout());
+        
+        if (finalCheck != null) {
+            LOG.info("starting final check");
+            finalCheck.run();
+        }
+    }
+
     /**
      * test basic integration with OFLib running the handshake
      *
@@ -100,35 +121,19 @@ public class SalIntegrationTest {
         LOG.debug("handshake integration test");
         LOG.debug("openflowPluginProvider: " + openflowPluginProvider);
 
-        SimpleClient switchSim = new SimpleClient("localhost", 6653);
         switchSim.setSecuredClient(false);
         ScenarioHandler scenario = new ScenarioHandler(ScenarioFactory.createHandshakeScenarioVBM(
                 ScenarioFactory.VERSION_BITMAP_13, (short) 0, ScenarioFactory.VERSION_BITMAP_10_13));
         switchSim.setScenarioHandler(scenario);
-        switchSim.run();
-
-        try {
-            LOG.debug("tearing down simulator");
-            switchSim.getScenarioDone().get(getFailSafeTimeout(), TimeUnit.MILLISECONDS);
-        } catch (Exception e) {
-            String msg = "waiting for scenario to finish failed: "+e.getMessage();
-            LOG.error(msg, e);
-            Assert.fail(msg);
-        }
-        
-        try {
-            LOG.debug("checking if simulator succeeded to connect to controller");
-            boolean simulatorWasOnline = switchSim.getIsOnlineFuture().get(100, TimeUnit.MILLISECONDS);
-            Assert.assertTrue("simulator failed to connect to controller", simulatorWasOnline);
-        } catch (Exception e) {
-            String message = "simulator probably failed to connect to controller";
-            LOG.error(message, e);
-            Assert.fail(message);
-        }
-        
-        Thread.sleep(1000);
-        assertEquals(1, listener.nodeUpdated.size());
-        assertNotNull(listener.nodeUpdated.get(0));
+        scenarioPool.execute(switchSim);
+
+        finalCheck = new Runnable() {
+            @Override
+            public void run() {
+                assertEquals(1, listener.nodeUpdated.size());
+                assertNotNull(listener.nodeUpdated.get(0));
+            }
+        };
     }
 
     /**
diff --git a/openflowplugin-it/src/test/java/org/opendaylight/openflowplugin/openflow/md/it/SimulatorAssistant.java b/openflowplugin-it/src/test/java/org/opendaylight/openflowplugin/openflow/md/it/SimulatorAssistant.java
new file mode 100644 (file)
index 0000000..bc6c8fd
--- /dev/null
@@ -0,0 +1,70 @@
+/**
+ * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.openflowplugin.openflow.md.it;
+
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+
+import org.junit.Assert;
+import org.opendaylight.openflowjava.protocol.impl.clients.SimpleClient;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * 
+ */
+public abstract class SimulatorAssistant {
+    
+    private static final Logger LOG = LoggerFactory
+            .getLogger(SimulatorAssistant.class);
+
+    /**
+     * @param switchSim 
+     * @throws InterruptedException
+     */
+    public static void waitForSwitchSimulatorOn(SimpleClient switchSim) {
+        try {
+            switchSim.getIsOnlineFuture().get(6, TimeUnit.SECONDS); // intentionally ignoring future inner value
+        } catch (TimeoutException | ExecutionException | InterruptedException e) {
+            LOG.error("failed to start switch simulator: {}", e.getMessage(), e);
+            Assert.fail("failed to start switch simulator");
+        }
+    }
+
+    /**
+     * @param switchSim 
+     * @param scenarioPool 
+     * @param failsafeTimeout 
+     */
+    public static void tearDownSwitchSimulatorAfterScenario(SimpleClient switchSim, ThreadPoolExecutor scenarioPool, long failsafeTimeout) {
+        try {
+            LOG.debug("tearing down simulator");
+            switchSim.getScenarioDone().get(failsafeTimeout, TimeUnit.MILLISECONDS);
+        } catch (Exception e) {
+            String msg = "waiting for scenario to finish failed: "+e.getMessage();
+            LOG.error(msg, e);
+            Assert.fail(msg);
+        } finally {
+            scenarioPool.shutdownNow();
+            scenarioPool.purge();
+        }
+    
+        try {
+            LOG.debug("checking if simulator succeeded to connect to controller");
+            boolean simulatorWasOnline = switchSim.getIsOnlineFuture().get(100, TimeUnit.MILLISECONDS);
+            Assert.assertTrue("simulator failed to connect to controller", simulatorWasOnline);
+        } catch (Exception e) {
+            String message = "simulator probably failed to connect to controller";
+            LOG.error(message, e);
+            Assert.fail(message);
+        }
+    }
+
+}
index ef88ccfaf8fd4b990832365f678c70ddc8bbb538..dba2e92a3f420dc54e1cd79cf5da33610e6e13e7 100644 (file)
@@ -8,6 +8,8 @@
 
 package org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.match;
 
+import static org.opendaylight.openflowjava.util.ByteBufUtils.macAddressToString;
+
 import com.google.common.base.Optional;
 import com.google.common.base.Splitter;
 import java.math.BigInteger;
@@ -654,17 +656,25 @@ public class MatchConvertorImpl implements MatchConvertor<List<MatchEntries>> {
                 }
             } else if (ofMatch.getOxmMatchField().equals(EthSrc.class)) {
                 MacAddressMatchEntry macAddressMatchEntry = ofMatch.getAugmentation(MacAddressMatchEntry.class);
+                final MaskMatchEntry sourceMask = ofMatch.getAugmentation(MaskMatchEntry.class);
                 if (macAddressMatchEntry != null) {
                     EthernetSourceBuilder ethSourceBuilder = new EthernetSourceBuilder();
                     ethSourceBuilder.setAddress(macAddressMatchEntry.getMacAddress());
+                    if (sourceMask != null) {
+                        ethSourceBuilder.setMask(new MacAddress(macAddressToString(sourceMask.getMask())));
+                    }
                     ethMatchBuilder.setEthernetSource(ethSourceBuilder.build());
                     matchBuilder.setEthernetMatch(ethMatchBuilder.build());
                 }
             } else if (ofMatch.getOxmMatchField().equals(EthDst.class)) {
                 MacAddressMatchEntry macAddressMatchEntry = ofMatch.getAugmentation(MacAddressMatchEntry.class);
+                final MaskMatchEntry destinationMask = ofMatch.getAugmentation(MaskMatchEntry.class);
                 if (macAddressMatchEntry != null) {
                     EthernetDestinationBuilder ethDestinationBuilder = new EthernetDestinationBuilder();
                     ethDestinationBuilder.setAddress(macAddressMatchEntry.getMacAddress());
+                    if (destinationMask != null) {
+                        ethDestinationBuilder.setMask(new MacAddress(macAddressToString(destinationMask.getMask())));
+                    }
                     ethMatchBuilder.setEthernetDestination(ethDestinationBuilder.build());
                     matchBuilder.setEthernetMatch(ethMatchBuilder.build());
                 }
index 98211f49b3b3c5ac9073dfdbbb1c261145839e97..99cb2ebd7f591968960b898fe1fb7c9027aceaf4 100644 (file)
@@ -448,7 +448,7 @@ public class MatchConvertorImplV13Test {
         macAddressBuilder.setMacAddress(new MacAddress("00:00:00:00:00:01"));\r
         entriesBuilder.addAugmentation(MacAddressMatchEntry.class, macAddressBuilder.build());\r
         maskBuilder = new MaskMatchEntryBuilder();\r
-        maskBuilder.setMask(new byte[]{0, 0, 0, 0, 0, 2});\r
+        maskBuilder.setMask(new byte[]{0, 0, 0, 0, 1, 1});\r
         entriesBuilder.addAugmentation(MaskMatchEntry.class, maskBuilder.build());\r
         entries.add(entriesBuilder.build());\r
         entriesBuilder = new MatchEntriesBuilder();\r
@@ -459,7 +459,7 @@ public class MatchConvertorImplV13Test {
         macAddressBuilder.setMacAddress(new MacAddress("00:00:00:00:00:02"));\r
         entriesBuilder.addAugmentation(MacAddressMatchEntry.class, macAddressBuilder.build());\r
         maskBuilder = new MaskMatchEntryBuilder();\r
-        maskBuilder.setMask(new byte[]{0, 0, 0, 0, 0, 3});\r
+        maskBuilder.setMask(new byte[]{0, 0, 0, 0, 2, 2});\r
         entriesBuilder.addAugmentation(MaskMatchEntry.class, maskBuilder.build());\r
         entries.add(entriesBuilder.build());\r
         entriesBuilder = new MatchEntriesBuilder();\r
@@ -529,9 +529,9 @@ public class MatchConvertorImplV13Test {
         Assert.assertEquals("Wrong metadata mask", new BigInteger(1, new byte[]{0, 0, 0, 0, 0, 0, 0, 1}),\r
                 builtMatch.getMetadata().getMetadataMask());\r
         Assert.assertEquals("Wrong eth dst", new MacAddress("00:00:00:00:00:01"), builtMatch.getEthernetMatch().getEthernetDestination().getAddress());\r
-//        Assert.assertEquals("Wrong eth dst mask", new MacAddress("00:00:00:00:00:01"), builtMatch.getEthernetMatch().getEthernetDestination().getMask());\r
+        Assert.assertEquals("Wrong eth dst mask", new MacAddress("00:00:00:00:01:01"), builtMatch.getEthernetMatch().getEthernetDestination().getMask());\r
         Assert.assertEquals("Wrong eth src", new MacAddress("00:00:00:00:00:02"), builtMatch.getEthernetMatch().getEthernetSource().getAddress());\r
-//        Assert.assertEquals("Wrong eth src mask", new MacAddress("00:00:00:00:00:03"), builtMatch.getEthernetMatch().getEthernetSource().getMask());\r
+        Assert.assertEquals("Wrong eth src mask", new MacAddress("00:00:00:00:02:02"), builtMatch.getEthernetMatch().getEthernetSource().getMask());\r
         Assert.assertEquals("Wrong vlan id", 4, builtMatch.getVlanMatch().getVlanId().getVlanId().getValue().intValue());\r
         Assert.assertEquals("Wrong vlan id entries", true, builtMatch.getVlanMatch().getVlanId().isVlanIdPresent());\r
         Ipv4Match ipv4Match = (Ipv4Match) builtMatch.getLayer3Match();\r
diff --git a/pom.xml b/pom.xml
index 593e80274564653c401a6edbcd7032a8d78db1f3..ce752b344533fdf61b16358cbab4e3631c47b1cf 100644 (file)
--- a/pom.xml
+++ b/pom.xml
           <artifactId>nagasena-rta</artifactId>
           <version>${exi.nagasena.version}</version>
         </dependency>
-        <dependency>
-          <groupId>org.opendaylight.controller.thirdparty</groupId>
-          <artifactId>ganymed</artifactId>
-          <version>1.2.0-SNAPSHOT</version>
-        </dependency>
         <dependency>
             <groupId>xml-apis</groupId>
             <artifactId>xml-apis</artifactId>