Merge "BUG 2661 - sonar issues in test-common artifact"
authormichal rehak <mirehak@cisco.com>
Fri, 13 Feb 2015 17:13:18 +0000 (17:13 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Fri, 13 Feb 2015 17:13:18 +0000 (17:13 +0000)
applications/topology-lldp-discovery/pom.xml
openflowplugin-it/pom.xml
openflowplugin-it/src/test/java/org/opendaylight/openflowplugin/openflow/md/it/OFPaxOptionsAssistant.java
openflowplugin-it/src/test/java/org/opendaylight/openflowplugin/openflow/md/it/OFPluginFlowTest.java [new file with mode: 0644]
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/ScenarioFactory.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/queue/QueueKeeperFactory.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 3e10e906f4394d9de925ad03cca7e790b9487796..182c42507e14d4ab2560d30ead17d3e613ef67e1 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>
             <artifactId>config-manager</artifactId>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>org.opendaylight.controller.md</groupId>
+            <artifactId>forwardingrules-manager</artifactId>
+            <scope>test</scope>
+            <version>${mdsal.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.opendaylight.controller.md</groupId>
+            <artifactId>inventory-manager</artifactId>
+            <scope>test</scope>
+            <version>${mdsal.version}</version>
+        </dependency>
         
         <dependency>
             <groupId>commons-codec</groupId>
index ed62919663ff933163aaf104a6711e968206854f..0ebcd0116764e9709f8100c4f8efcf51a1d922df 100644 (file)
@@ -27,6 +27,8 @@ public abstract class OFPaxOptionsAssistant {
     public static final String DEBUG_PORT = "6000";
     /** base controller package */
     public static final String CONTROLLER = "org.opendaylight.controller";
+    /** base controller.md package */
+    public static final String CONTROLLER_MD = "org.opendaylight.controller.md";
     /** OFLibrary package */
     public static final String OFLIBRARY = "org.opendaylight.openflowjava";
     /** OFLibrary package */
@@ -79,6 +81,8 @@ public abstract class OFPaxOptionsAssistant {
                 mavenBundle(OFPLUGIN, "openflowplugin-api").versionAsInProject(),
                 mavenBundle(OFPLUGIN, "openflowplugin-extension-api").versionAsInProject(),
                 mavenBundle(OFPLUGIN, "openflowplugin").versionAsInProject(),
+                mavenBundle(CONTROLLER_MD, "forwardingrules-manager").versionAsInProject(),
+                mavenBundle(CONTROLLER_MD, "inventory-manager").versionAsInProject(),
                 mavenBundle("org.openexi", "nagasena").versionAsInProject()
                 );
     }
diff --git a/openflowplugin-it/src/test/java/org/opendaylight/openflowplugin/openflow/md/it/OFPluginFlowTest.java b/openflowplugin-it/src/test/java/org/opendaylight/openflowplugin/openflow/md/it/OFPluginFlowTest.java
new file mode 100644 (file)
index 0000000..4cd426c
--- /dev/null
@@ -0,0 +1,374 @@
+/**
+ * Copyright (c) 2013 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 static org.ops4j.pax.exam.CoreOptions.options;
+import static org.ops4j.pax.exam.CoreOptions.systemProperty;
+
+import java.math.BigInteger;
+import java.util.ArrayList;
+import java.util.Deque;
+import java.util.List;
+import java.util.Set;
+import java.util.concurrent.ArrayBlockingQueue;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+
+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;
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.binding.api.DataChangeListener;
+import org.opendaylight.controller.md.sal.binding.api.ReadTransaction;
+import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
+import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker.DataChangeScope;
+import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
+import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
+import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
+import org.opendaylight.controller.test.sal.binding.it.TestHelper;
+import org.opendaylight.openflowjava.protocol.impl.clients.ClientEvent;
+import org.opendaylight.openflowjava.protocol.impl.clients.ScenarioHandler;
+import org.opendaylight.openflowjava.protocol.impl.clients.SimpleClient;
+import org.opendaylight.openflowjava.protocol.impl.clients.SleepEvent;
+import org.opendaylight.openflowjava.protocol.impl.clients.WaitForMessageEvent;
+import org.opendaylight.openflowjava.util.ByteBufUtils;
+import org.opendaylight.openflowplugin.openflow.md.core.ThreadPoolLoggingExecutor;
+import org.opendaylight.openflowplugin.openflow.md.core.sal.OpenflowPluginProvider;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Prefix;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.DecNwTtlCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.dec.nw.ttl._case.DecNwTtl;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.dec.nw.ttl._case.DecNwTtlBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowCookie;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowModFlags;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.InstructionsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.ApplyActionsCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.apply.actions._case.ApplyActionsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.InstructionBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.InstructionKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.EtherType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetTypeBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatchBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4Match;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4MatchBuilder;
+import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.ops4j.pax.exam.Configuration;
+import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.junit.PaxExam;
+import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
+import org.ops4j.pax.exam.spi.reactors.PerClass;
+import org.ops4j.pax.exam.util.Filter;
+import org.osgi.framework.BundleContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.Optional;
+import com.google.common.util.concurrent.CheckedFuture;
+import com.google.common.util.concurrent.FutureCallback;
+import com.google.common.util.concurrent.Futures;
+
+/**
+ * covers basic handshake scenarios
+ */
+@RunWith(PaxExam.class)
+@ExamReactorStrategy(PerClass.class)
+public class OFPluginFlowTest {
+
+    static final Logger LOG = LoggerFactory
+            .getLogger(OFPluginFlowTest.class);
+
+    private static final ArrayBlockingQueue<Runnable> SCENARIO_POOL_QUEUE = new ArrayBlockingQueue<>(1);
+
+    @Inject @Filter(timeout=20000)
+    OpenflowPluginProvider openflowPluginProvider;
+
+    @Inject
+    BundleContext ctx;
+    
+    @Inject @Filter(timeout=20000)
+    static DataBroker dataBroker;
+    @Inject @Filter(timeout=20000)
+    NotificationProviderService notificationService;
+    
+    private SimpleClient switchSim;
+    private ThreadPoolLoggingExecutor scenarioPool;
+
+    /**
+     * test setup
+     * @throws InterruptedException
+     */
+    @Before
+    public void setUp() throws InterruptedException {
+        LOG.debug("openflowPluginProvider: "+openflowPluginProvider);
+        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);
+    }
+
+    /**
+     * test tear down
+     */
+    @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);
+        }
+    }
+
+    final class TriggerTestListener implements DataChangeListener {
+
+        public TriggerTestListener() {
+            // NOOP
+        }
+
+        @Override
+        public void onDataChanged(
+                AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> arg0) {
+            Set<InstanceIdentifier<?>> keySet = arg0.getCreatedData().keySet();
+            if (keySet.size() == 1) {
+                for (InstanceIdentifier<?> key : keySet) {
+                    InstanceIdentifier<FlowCapableNode> neededKey =
+                            key.firstIdentifierOf(FlowCapableNode.class);
+                    if (neededKey != null) {
+                        LOG.info("Node was added (brm) {}", neededKey);
+                        writeFlow(createTestFlow(), neededKey);
+                        break;
+                    }
+                }
+            }
+        }
+    }
+    
+    /**
+     * test basic integration with OFLib running the handshake
+     * @throws Exception
+     */
+    @Test
+    public void testFlowMod() throws Exception {
+        LOG.debug("testFlowMod integration test");
+        TriggerTestListener brmListener = new TriggerTestListener();
+        
+        dataBroker.registerDataChangeListener(LogicalDatastoreType.OPERATIONAL,
+                getWildcardPath(), brmListener, DataChangeScope.BASE);
+        
+        switchSim = createSimpleClient();
+        switchSim.setSecuredClient(false);
+        Deque<ClientEvent> handshakeScenario = ScenarioFactory.createHandshakeScenarioVBM(
+                ScenarioFactory.VERSION_BITMAP_13, (short) 0, ScenarioFactory.VERSION_BITMAP_10_13, false);
+        handshakeScenario.addFirst(new SleepEvent(3000L));
+        ScenarioFactory.appendPostHandshakeScenario(handshakeScenario, true);
+        WaitForMessageEvent flowModEvent = new WaitForMessageEvent(ByteBufUtils
+                .hexStringToBytes(
+                        "04 0e 00 58 00 00 00 05 00 00 00 00 00 00 00 0a "
+                        + "00 00 00 00 00 00 00 0a 00 00 00 00 00 00 80 00 "
+                        + "ff ff ff ff ff ff ff ff ff ff ff ff 00 01 00 00 "
+                        + "00 01 00 16 80 00 0a 02 08 00 80 00 19 08 0a 00 "
+                        + "00 01 ff ff ff 00 00 00 00 04 00 10 00 00 00 00 "
+                        + "00 18 00 08 00 00 00 00"));
+        handshakeScenario.addFirst(flowModEvent);
+        ScenarioHandler scenario = new ScenarioHandler(handshakeScenario);
+        switchSim.setScenarioHandler(scenario);
+        scenarioPool.execute(switchSim);
+        LOG.info("finishing testFlowMod");
+    }
+
+    private static InstanceIdentifier<?> getWildcardPath() {
+        return InstanceIdentifier.create(Nodes.class).child(Node.class).augmentation(FlowCapableNode.class);
+    }
+
+    /**
+     * @return
+     */
+    private static SimpleClient createSimpleClient() {
+        return new SimpleClient("localhost", 6653);
+    }
+
+    /**
+     * @return timeout for case of failure
+     */
+    private static long getFailSafeTimeout() {
+        return 20000;
+    }
+
+
+    /**
+     * @return bundle options
+     */
+    @Configuration
+    public Option[] config() {
+        LOG.info("configuring...");
+        return options(
+                systemProperty("osgi.console").value("2401"),
+                systemProperty("osgi.bundles.defaultStartLevel").value("4"),
+                systemProperty("pax.exam.osgi.unresolved.fail").value("true"),
+
+                OFPaxOptionsAssistant.osgiConsoleBundles(),
+                OFPaxOptionsAssistant.loggingBudles(),
+
+                TestHelper.junitAndMockitoBundles(),
+                TestHelper.mdSalCoreBundles(),
+                TestHelper.configMinumumBundles(),
+                TestHelper.baseModelBundles(),
+                TestHelper.flowCapableModelBundles(),
+
+                OFPaxOptionsAssistant.ofPluginBundles());
+    }
+    
+    static FlowBuilder createTestFlow() {
+        short tableId = 0;
+        FlowBuilder flow = new FlowBuilder();
+        flow.setMatch(createMatch1().build());
+        flow.setInstructions(createDecNwTtlInstructions().build());
+        
+        FlowId flowId = new FlowId("127");
+        FlowKey key = new FlowKey(flowId);
+        if (null == flow.isBarrier()) {
+            flow.setBarrier(Boolean.FALSE);
+        }
+        BigInteger value = BigInteger.TEN;
+        flow.setCookie(new FlowCookie(value));
+        flow.setCookieMask(new FlowCookie(value));
+        flow.setHardTimeout(0);
+        flow.setIdleTimeout(0);
+        flow.setInstallHw(false);
+        flow.setStrict(false);
+        flow.setContainerName(null);
+        flow.setFlags(new FlowModFlags(false, false, false, false, true));
+        flow.setId(flowId);
+        flow.setTableId(tableId);
+
+        flow.setKey(key);
+        flow.setFlowName("Foo" + "X" + "f1");
+        
+        return flow;
+    }
+    
+    private static MatchBuilder createMatch1() {
+        MatchBuilder match = new MatchBuilder();
+        Ipv4MatchBuilder ipv4Match = new Ipv4MatchBuilder();
+        Ipv4Prefix prefix = new Ipv4Prefix("10.0.0.1/24");
+        ipv4Match.setIpv4Destination(prefix);
+        Ipv4Match i4m = ipv4Match.build();
+        match.setLayer3Match(i4m);
+
+        EthernetMatchBuilder eth = new EthernetMatchBuilder();
+        EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
+        ethTypeBuilder.setType(new EtherType(0x0800L));
+        eth.setEthernetType(ethTypeBuilder.build());
+        match.setEthernetMatch(eth.build());
+        return match;
+    }
+    
+    private static InstructionsBuilder createDecNwTtlInstructions() {
+        DecNwTtlBuilder ta = new DecNwTtlBuilder();
+        DecNwTtl decNwTtl = ta.build();
+        ActionBuilder ab = new ActionBuilder();
+        ab.setAction(new DecNwTtlCaseBuilder().setDecNwTtl(decNwTtl).build());
+        ab.setKey(new ActionKey(0));
+        // Add our drop action to a list
+        List<Action> actionList = new ArrayList<Action>();
+        actionList.add(ab.build());
+
+        // Create an Apply Action
+        ApplyActionsBuilder aab = new ApplyActionsBuilder();
+        aab.setAction(actionList);
+
+        // Wrap our Apply Action in an Instruction
+        InstructionBuilder ib = new InstructionBuilder();
+        ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
+        ib.setKey(new InstructionKey(0));
+        ib.setOrder(0);
+
+        // Put our Instruction in a list of Instructions
+        InstructionsBuilder isb = new InstructionsBuilder();
+        List<Instruction> instructions = new ArrayList<Instruction>();
+        instructions.add(ib.build());
+        ib.setKey(new InstructionKey(0));
+        isb.setInstruction(instructions);
+        return isb;
+    }
+    
+    static void writeFlow(FlowBuilder flow, InstanceIdentifier<FlowCapableNode> flowNodeIdent) { 
+        ReadWriteTransaction modification = dataBroker.newReadWriteTransaction();
+        final InstanceIdentifier<Flow> path1 = flowNodeIdent.child(Table.class, new TableKey(flow.getTableId()))
+                .child(Flow.class, flow.getKey());
+        modification.merge(LogicalDatastoreType.CONFIGURATION, path1, flow.build(), true);
+        CheckedFuture<Void, TransactionCommitFailedException> commitFuture = modification.submit();
+        Futures.addCallback(commitFuture, new FutureCallback<Void>() {
+            @Override
+            public void onSuccess(Void aVoid) {
+                LOG.debug("Write of flow on device succeeded.");
+            }
+
+            @Override
+            public void onFailure(Throwable throwable) {
+                LOG.error("Write of flow on device failed.", throwable);
+            }
+        });
+    }
+    
+    //TODO move to separate test util class
+    private final static Flow readFlow(InstanceIdentifier<Flow> flow) {
+        Flow searchedFlow = null;
+        ReadTransaction rt = dataBroker.newReadOnlyTransaction();
+        CheckedFuture<Optional<Flow>, ReadFailedException> flowFuture =
+            rt.read(LogicalDatastoreType.CONFIGURATION, flow);
+        
+        try {
+          Optional<Flow> maybeFlow = flowFuture.checkedGet(500, TimeUnit.SECONDS);
+          if(maybeFlow.isPresent()) {
+              searchedFlow = maybeFlow.get();
+          }
+        } catch (TimeoutException e) {
+          LOG.error("Future timed out. Getting FLOW from DataStore failed.", e);
+        } catch (ReadFailedException e) {
+          LOG.error("Something wrong happened in DataStore. Getting FLOW for userId {} failed.", e);
+        }
+        
+        return searchedFlow;
+    }
+}
index 774cd1ae37352bc59ed74477f7f465b8a8f8ab36..982f9e73d5a5f14b259ee049c79d5b6a4126da69 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,10 +86,9 @@ 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);
+                ScenarioFactory.VERSION_BITMAP_13, (short) 0, ScenarioFactory.VERSION_BITMAP_10_13, true);
 
         ScenarioHandler scenario = new ScenarioHandler(handshakeScenario);
         switchSim.setScenarioHandler(scenario);
index 9091ca430bdb3382e0deb847ed5ae53bdf278795..9211817889d417e13a77caf2c19a45b3e9b71752 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));
+                ScenarioFactory.VERSION_BITMAP_13, (short) 0, ScenarioFactory.VERSION_BITMAP_10_13, true));
         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));
+            }
+        };
     }
 
     /**
index a0cb314737ddb1dbfbe6fdf74c6c76f42b12997b..a6fe35f9bb0629f5fe75d7722f08331a044aa5a7 100644 (file)
@@ -21,6 +21,8 @@ import org.opendaylight.openflowjava.util.ByteBufUtils;
  */
 public abstract class ScenarioFactory {
 
+    /** default sleep time [ms] - at scenario end */
+    public static final int DEFAULT_SCENARIO_SLEEP = 2000;
     /** version bitmap hex-string containing version 1.3 */
     public static final String VERSION_BITMAP_13 = "00 01 00 08 00 00 00 10";
     /** version bitmap hex-string containing versions: 1.0 + 1.3 */
@@ -37,10 +39,11 @@ public abstract class ScenarioFactory {
      * @param switchVersionBitmap
      * @param auxId
      * @param pluginVersionBitmap
+     * @param addSleep if true - then add final sleep {@link #DEFAULT_SCENARIO_SLEEP} 
      * @return stack filled with Handshake messages
      */
     public static Deque<ClientEvent> createHandshakeScenarioVBM(
-            String switchVersionBitmap, short auxId, String pluginVersionBitmap) {
+            String switchVersionBitmap, short auxId, String pluginVersionBitmap, boolean addSleep) {
         Deque<ClientEvent> stack = new ArrayDeque<>();
 
         stack.addFirst(new SendEvent(ByteBufUtils
@@ -56,15 +59,45 @@ public abstract class ScenarioFactory {
                         + "00 01 02 03 04 05 06 07 " + "00 01 02 03 01 "
                         + Integer.toHexString(auxId)
                         + " 00 00 00 01 02 03 00 01 02 03")));
-        addSleep(stack);
+        
+        if (addSleep) {
+            addSleep(stack);
+        }
+        
         return stack;
     }
-
+    
+    /**
+     * @param stack
+     * @param addSleep if true - then add final sleep {@link #DEFAULT_SCENARIO_SLEEP}
+     * @return
+     */
+    public static Deque<ClientEvent> appendPostHandshakeScenario(Deque<ClientEvent> stack, boolean addSleep) {
+        stack.addFirst(new WaitForMessageEvent(ByteBufUtils
+                .hexStringToBytes("04 12 00 10 00 00 00 01 "+
+                                  "00 0d 00 00 00 00 00 00"  )));
+        stack.addFirst(new WaitForMessageEvent(ByteBufUtils
+                .hexStringToBytes("04 12 00 10 00 00 00 02 "+
+                                  "00 08 00 00 00 00 00 00"  )));
+        stack.addFirst(new WaitForMessageEvent(ByteBufUtils
+                .hexStringToBytes("04 12 00 10 00 00 00 03 "+
+                                  "00 0b 00 00 00 00 00 00"  )));
+        stack.addFirst(new WaitForMessageEvent(ByteBufUtils
+                .hexStringToBytes("04 12 00 10 00 00 00 04 "+
+                                  "00 00 00 00 00 00 00 00"  )));
+        
+        if (addSleep) {
+            addSleep(stack);
+        }
+        
+        return stack;
+    }
+    
     /**
      * @param stack
      */
     private static void addSleep(Deque<ClientEvent> stack) {
-        stack.addFirst(new SleepEvent(2000));
+        stack.addFirst(new SleepEvent(DEFAULT_SCENARIO_SLEEP));
     }
 
     /**
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 879f86dc249ab931f6a559c897d9033e260d2f20..0c856cff298e2f502090d6a4815f0f9529dbea9a 100644 (file)
@@ -41,5 +41,6 @@ public abstract class QueueKeeperFactory {
             QueueKeeper<V> queueKeeper) {
         AutoCloseable registration = sourceRegistrator.registerMessageSource(queueKeeper);
         queueKeeper.setPollRegistration(registration);
+        sourceRegistrator.getHarvesterHandle().ping();
     }
 }
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>