Merge "BUG-2661: Sonar issue"
authormichal rehak <mirehak@cisco.com>
Fri, 13 Feb 2015 17:13:43 +0000 (17:13 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Fri, 13 Feb 2015 17:13:44 +0000 (17:13 +0000)
21 files changed:
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/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/core/sal/convertor/match/MatchConvertorImpl.java
openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/queue/QueueKeeperFactory.java
openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/match/MatchConvertorImplV13Test.java
pom.xml
test-common/pom.xml
test-common/src/main/java/org/opendaylight/openflowplugin/testcommon/AbstractDropTest.java
test-common/src/main/java/org/opendaylight/openflowplugin/testcommon/DropTestCommiter.java
test-common/src/main/java/org/opendaylight/openflowplugin/testcommon/DropTestDsProvider.java
test-common/src/main/java/org/opendaylight/openflowplugin/testcommon/DropTestRpcProvider.java
test-common/src/main/java/org/opendaylight/openflowplugin/testcommon/DropTestRpcSender.java
test-common/src/main/java/org/opendaylight/openflowplugin/testcommon/DropTestStats.java
test-common/src/main/java/org/opendaylight/openflowplugin/testcommon/DropTestUtils.java [deleted file]

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..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 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 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();
     }
 }
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>
index 5309c6d40cd838831e34b8e07fcf27de5afccab4..14cc75fbb81fc82d2b4f5b9f8991ab65cb2b1418 100644 (file)
             <groupId>org.opendaylight.controller.model</groupId>
             <artifactId>model-inventory</artifactId>
         </dependency>
+        <dependency>
+            <groupId>org.opendaylight.openflowjava</groupId>
+            <artifactId>util</artifactId>
+        </dependency>
     </dependencies>
 
     <build>
index 298199ebff78b0b4fdea625635bd585314af9a82..4707573098f9a86a55f53cc7d219961878e6c8be 100644 (file)
@@ -7,11 +7,12 @@
  */
 package org.opendaylight.openflowplugin.testcommon;
 
+import static org.opendaylight.openflowjava.util.ByteBufUtils.macAddressToString;
+
 import java.util.Arrays;
 import java.util.Collections;
 import java.util.List;
 import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
-
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.DropActionCaseBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.drop.action._case.DropAction;
@@ -40,23 +41,29 @@ import org.slf4j.LoggerFactory;
 abstract class AbstractDropTest implements PacketProcessingListener, AutoCloseable {
     private static final Logger LOG = LoggerFactory.getLogger(AbstractDropTest.class);
 
-    private static final AtomicIntegerFieldUpdater<AbstractDropTest> SENT_UPDATER = AtomicIntegerFieldUpdater.newUpdater(AbstractDropTest.class, "_sent");
-    private volatile int _sent;
+    protected static final Integer PRIORITY = 4;
+    protected static final Long BUFFER_ID = 0L;
+    protected static final Integer HARD_TIMEOUT = 300;
+    protected static final Integer IDLE_TIMEOUT = 240;
+    protected static final short TABLE_ID = 0;
+
+    private static final AtomicIntegerFieldUpdater<AbstractDropTest> SENT_UPDATER = AtomicIntegerFieldUpdater.newUpdater(AbstractDropTest.class, "sent");
+    private volatile int sent;
 
-    private static final AtomicIntegerFieldUpdater<AbstractDropTest> RCVD_UPDATER = AtomicIntegerFieldUpdater.newUpdater(AbstractDropTest.class, "_rcvd");
-    private volatile int _rcvd;
+    private static final AtomicIntegerFieldUpdater<AbstractDropTest> RCVD_UPDATER = AtomicIntegerFieldUpdater.newUpdater(AbstractDropTest.class, "rcvd");
+    private volatile int rcvd;
 
-    private static final AtomicIntegerFieldUpdater<AbstractDropTest> EXCS_UPDATER = AtomicIntegerFieldUpdater.newUpdater(AbstractDropTest.class, "_excs");
-    private volatile int _excs;
+    private static final AtomicIntegerFieldUpdater<AbstractDropTest> EXCS_UPDATER = AtomicIntegerFieldUpdater.newUpdater(AbstractDropTest.class, "excs");
+    private volatile int excs;
 
     public final DropTestStats getStats() {
-        return new DropTestStats(this._sent, this._rcvd, this._excs);
+        return new DropTestStats(this.sent, this.rcvd, this.excs);
     }
 
     public final void clearStats(){
-        this._sent = 0;
-        this._rcvd = 0;
-        this._excs = 0;
+        this.sent = 0;
+        this.rcvd = 0;
+        this.excs = 0;
     }
 
     @Override
@@ -67,15 +74,8 @@ abstract class AbstractDropTest implements PacketProcessingListener, AutoCloseab
 
         try {
             final byte[] rawPacket = notification.getPayload();
-
-            // LOG.debug("onPacketReceived - received Packet on Node {} and NodeConnector {} payload {}",
-            //        nodeKey.getId(), ncKey.getId(), Hex.encodeHexString(rawPacket));
-
             final byte[] srcMac = Arrays.copyOfRange(rawPacket, 6, 12);
 
-            //LOG.debug("onPacketReceived - received Packet on Node {} and NodeConnector {} srcMac {}",
-            //        nodeKey.getId(), ncKey.getId(), Hex.encodeHexString(srcMac));
-
             final MatchBuilder match = new MatchBuilder();
             final EthernetMatchBuilder ethernetMatch = new EthernetMatchBuilder();
             final EthernetSourceBuilder ethSourceBuilder = new EthernetSourceBuilder();
@@ -83,7 +83,7 @@ abstract class AbstractDropTest implements PacketProcessingListener, AutoCloseab
             //TODO: use HEX, use binary form
             //Hex.decodeHex("000000000001".toCharArray());
 
-            ethSourceBuilder.setAddress(new MacAddress(DropTestUtils.macToString(srcMac)));
+            ethSourceBuilder.setAddress(new MacAddress(macAddressToString(srcMac)));
             ethernetMatch.setEthernetSource(ethSourceBuilder.build());
             match.setEthernetMatch(ethernetMatch.build());
 
index 8d53174290695b0e642219425a549ce3750d014f..28ee0ee92e10fb1856dbf5398f477074bfb7e924 100644 (file)
@@ -9,7 +9,6 @@ package org.opendaylight.openflowplugin.testcommon;
 
 import java.math.BigInteger;
 import java.util.concurrent.atomic.AtomicLong;
-
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
@@ -35,30 +34,30 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 /**
- * provides cbench responder behavior: upon packetIn arrival addFlow action is sent out to 
+ * provides cbench responder behavior: upon packetIn arrival addFlow action is sent out to
  * device using dataStore strategy (FRM involved)
  */
 public class DropTestCommiter extends AbstractDropTest {
-    private final static Logger LOG = LoggerFactory.getLogger(DropTestCommiter.class);
-    
+    private static final Logger LOG = LoggerFactory.getLogger(DropTestCommiter.class);
+
     private DataBroker dataService;
-    
-    private static final AtomicLong idCounter = new AtomicLong();
+
+    private static final AtomicLong ID_COUNTER = new AtomicLong();
 
     private static final ThreadLocal<FlowBuilder> BUILDER = new ThreadLocal<FlowBuilder>() {
         @Override
         protected FlowBuilder initialValue() {
             final FlowBuilder fb = new FlowBuilder();
 
-            fb.setPriority(4);
-            fb.setBufferId(0L);
+            fb.setPriority(PRIORITY);
+            fb.setBufferId(BUFFER_ID);
             final FlowCookie cookie = new FlowCookie(BigInteger.TEN);
             fb.setCookie(cookie);
             fb.setCookieMask(cookie);
 
-            fb.setTableId((short) 0);
-            fb.setHardTimeout(300);
-            fb.setIdleTimeout(240);
+            fb.setTableId(TABLE_ID);
+            fb.setHardTimeout(HARD_TIMEOUT);
+            fb.setIdleTimeout(IDLE_TIMEOUT);
             fb.setFlags(new FlowModFlags(false, false, false, false, false));
             return fb;
         }
@@ -67,14 +66,14 @@ public class DropTestCommiter extends AbstractDropTest {
     private NotificationProviderService notificationService;
 
     private ListenerRegistration<NotificationListener> notificationRegistration;
-    
+
     /**
      * start listening on packetIn
      */
     public void start() {
         notificationRegistration = notificationService.registerNotificationListener(this);
     }
-    
+
     /**
      * @param dataService the dataService to set
      */
@@ -89,15 +88,20 @@ public class DropTestCommiter extends AbstractDropTest {
         final FlowBuilder fb = BUILDER.get();
         fb.setMatch(match);
         fb.setInstructions(instructions);
-        fb.setId(new FlowId(String.valueOf(fb.hashCode()) +"."+ String.valueOf(idCounter.getAndIncrement())));
-        
+        fb.setId(new FlowId(String.valueOf(fb.hashCode()) +"."+ ID_COUNTER.getAndIncrement()));
+
         // Construct the flow instance id
         final InstanceIdentifier<Flow> flowInstanceId =
-                InstanceIdentifier.builder(Nodes.class) // File under nodes
-                        .child(Node.class, node) // A particular node identified by nodeKey
-                        .augmentation(FlowCapableNode.class) // That is flow capable, only FlowCapableNodes have tables
-                        .child(Table.class, new TableKey((short) 0)) // In the table identified by TableKey
-                        .child(Flow.class, new FlowKey(fb.getId())) // A flow identified by flowKey
+                // File under nodes
+                InstanceIdentifier.builder(Nodes.class)
+                        // A particular node identified by nodeKey
+                        .child(Node.class, node)
+                        // That is flow capable, only FlowCapableNodes have tables
+                        .augmentation(FlowCapableNode.class)
+                        // In the table identified by TableKey
+                        .child(Table.class, new TableKey((short) 0))
+                        // A flow identified by flowKey
+                        .child(Flow.class, new FlowKey(fb.getId()))
                         .build();
 
         final Flow flow = fb.build();
@@ -110,7 +114,7 @@ public class DropTestCommiter extends AbstractDropTest {
         transaction.submit();
         LOG.debug("onPacketReceived - About to write flow commited");
     }
-    
+
     @Override
     public void close() {
         try {
index a4d6f46764d03ad9a2d4f8fc659c1e4aeacbc0a2..adf2cee69c661510c1cb2b9034f6277ca583906d 100644 (file)
@@ -16,7 +16,7 @@ import org.slf4j.LoggerFactory;
  * provides activation and deactivation of drop responder service - responds on packetIn
  */
 public class DropTestDsProvider implements AutoCloseable {
-    private final static Logger LOG = LoggerFactory.getLogger(DropTestDsProvider.class);
+    private static final Logger LOG = LoggerFactory.getLogger(DropTestDsProvider.class);
 
     private DataBroker dataService;
     private NotificationProviderService notificationService;
@@ -71,7 +71,7 @@ public class DropTestDsProvider implements AutoCloseable {
             active = false;
         }
     }
-    
+
     /**
      * @return the active
      */
index 1fd7926f173139c26018e1715309296f9cceda73..352f61410edebdf6026c8aa2c9f8e4aed6c2b9f0 100644 (file)
@@ -16,7 +16,7 @@ import org.slf4j.LoggerFactory;
  * provides activation and deactivation of drop responder service - responds on packetIn
  */
 public class DropTestRpcProvider implements AutoCloseable {
-    private final static Logger LOG = LoggerFactory.getLogger(DropTestDsProvider.class);
+    private static final Logger LOG = LoggerFactory.getLogger(DropTestDsProvider.class);
 
     private SalFlowService flowService;
     private NotificationProviderService notificationService;
@@ -76,7 +76,7 @@ public class DropTestRpcProvider implements AutoCloseable {
             active = false;
         }
     }
-    
+
     /**
      * @return the active
      */
index 841d1c88744fc1f917346e699ff4ae8ede287371..30089b69a18688d694648d85ffac5c17c0682167 100644 (file)
@@ -7,8 +7,13 @@
  */
 package org.opendaylight.openflowplugin.testcommon;
 
-import java.math.BigInteger;
+import static org.opendaylight.openflowplugin.testcommon.AbstractDropTest.BUFFER_ID;
+import static org.opendaylight.openflowplugin.testcommon.AbstractDropTest.HARD_TIMEOUT;
+import static org.opendaylight.openflowplugin.testcommon.AbstractDropTest.IDLE_TIMEOUT;
+import static org.opendaylight.openflowplugin.testcommon.AbstractDropTest.PRIORITY;
+import static org.opendaylight.openflowplugin.testcommon.AbstractDropTest.TABLE_ID;
 
+import java.math.BigInteger;
 import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInputBuilder;
@@ -28,14 +33,14 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 /**
- * provides cbench responder behavior: upon packetIn arrival addFlow action is sent out to 
+ * provides cbench responder behavior: upon packetIn arrival addFlow action is sent out to
  * device using {@link SalFlowService} strategy
  */
 public class DropTestRpcSender extends AbstractDropTest {
-    private final static Logger LOG = LoggerFactory.getLogger(DropTestRpcSender.class);
+    private static final Logger LOG = LoggerFactory.getLogger(DropTestRpcSender.class);
 
     private SalFlowService flowService;
-    
+
     /**
      * @param flowService the flowService to set
      */
@@ -48,15 +53,15 @@ public class DropTestRpcSender extends AbstractDropTest {
         protected AddFlowInputBuilder initialValue() {
             final AddFlowInputBuilder fb = new AddFlowInputBuilder();
 
-            fb.setPriority(4);
-            fb.setBufferId(0L);
+            fb.setPriority(PRIORITY);
+            fb.setBufferId(BUFFER_ID);
 
             final FlowCookie cookie = new FlowCookie(BigInteger.TEN);
             fb.setCookie(cookie);
             fb.setCookieMask(cookie);
-            fb.setTableId((short) 0);
-            fb.setHardTimeout(300);
-            fb.setIdleTimeout(240);
+            fb.setTableId(TABLE_ID);
+            fb.setHardTimeout(HARD_TIMEOUT);
+            fb.setIdleTimeout(IDLE_TIMEOUT);
             fb.setFlags(new FlowModFlags(false, false, false, false, false));
 
             return fb;
@@ -66,7 +71,7 @@ public class DropTestRpcSender extends AbstractDropTest {
     private NotificationProviderService notificationService;
 
     private ListenerRegistration<NotificationListener> notificationRegistration;
-    
+
     /**
      * start listening on packetIn
      */
@@ -85,8 +90,10 @@ public class DropTestRpcSender extends AbstractDropTest {
 
         // Construct the flow instance id
         final InstanceIdentifier<Node> flowInstanceId = InstanceIdentifier
-                .builder(Nodes.class) // File under nodes
-                .child(Node.class, node).build(); // A particular node identified by nodeKey
+                // File under nodes
+                .builder(Nodes.class)
+                // A particular node identified by nodeKey
+                .child(Node.class, node).build();
         fb.setNode(new NodeRef(flowInstanceId));
 
         // Add flow
@@ -103,7 +110,7 @@ public class DropTestRpcSender extends AbstractDropTest {
     public void setNotificationService(NotificationProviderService notificationService) {
         this.notificationService = notificationService;
     }
-    
+
     @Override
     public void close() {
         try {
index 2fb13e0e429bc6ea58379634e0b0679434d62e70..a3cb9665c4c83465da219cd32caa08d07ab737e9 100644 (file)
@@ -1,48 +1,51 @@
 package org.opendaylight.openflowplugin.testcommon;
 
 public class DropTestStats {
-       private final int _rcvd;
-       private final int _sent;
-       private final int _excs;
-       private final String _message;
-
-       public DropTestStats(int sent, int rcvd) {
-               this._sent = sent;
-               this._rcvd = rcvd;
-               this._excs = 0;
-               this._message = null;
-       }
-       
-       public DropTestStats(int sent, int rcvd, int excs) {
-               this._sent = sent;
-               this._rcvd = rcvd;
-               this._excs = excs;
-               this._message = null;
-       }
-
-               public DropTestStats(String message) {
-               this._sent = -1;
-               this._rcvd = -1;
-               this._excs = -1;
-               this._message = message;
-       }
-       
-       public int getSent() { return this._sent; }
-       public int getRcvd() { return this._rcvd; }
-       public String getMessage() { return this._message; };
-
-       @Override 
-       public String toString() {
-           StringBuilder result = new StringBuilder();
-           if (this._message == null) {
-               result.append("Rcvd: " + this._rcvd);
-               result.append(", Sent: " + this._sent);
-               result.append("; Exceptions: " + this._excs);
-           } else {
-               result.append(this._message);
-           }
-               
-               return result.toString();
-       }
-       
+    private final int rcvd;
+    private final int sent;
+    private final int excs;
+    private final String message;
+
+    public DropTestStats(int sent, int rcvd) {
+        this.sent = sent;
+        this.rcvd = rcvd;
+        this.excs = 0;
+        this.message = null;
+    }
+
+    public DropTestStats(int sent, int rcvd, int excs) {
+        this.sent = sent;
+        this.rcvd = rcvd;
+        this.excs = excs;
+        this.message = null;
+    }
+
+        public DropTestStats(String message) {
+        this.sent = -1;
+        this.rcvd = -1;
+        this.excs = -1;
+        this.message = message;
+    }
+
+    public int getSent() { return this.sent; }
+    public int getRcvd() { return this.rcvd; }
+    public String getMessage() { return this.message; }
+
+    @Override
+    public String toString() {
+        StringBuilder result = new StringBuilder();
+        if (this.message == null) {
+            result.append("Rcvd: ");
+            result.append(this.rcvd);
+            result.append(", Sent: ");
+            result.append(this.sent);
+            result.append("; Exceptions: ");
+            result.append(this.excs);
+        } else {
+            result.append(this.message);
+        }
+
+        return result.toString();
+    }
+
 }
diff --git a/test-common/src/main/java/org/opendaylight/openflowplugin/testcommon/DropTestUtils.java b/test-common/src/main/java/org/opendaylight/openflowplugin/testcommon/DropTestUtils.java
deleted file mode 100644 (file)
index adce890..0000000
+++ /dev/null
@@ -1,35 +0,0 @@
-/**
- * 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.testcommon;
-
-import com.google.common.base.Preconditions;
-import com.google.common.primitives.UnsignedBytes;
-
-public class DropTestUtils {
-    private static final char[] HEX = "0123456789ABCDEF".toCharArray();
-
-    private static final void appendByte(final StringBuilder sb, final byte b) {
-        int v = UnsignedBytes.toInt(b);
-        sb.append(HEX[v >>> 4]);
-        sb.append(HEX[v & 15]);
-    }
-
-    public static String macToString(final byte[] mac) {
-        Preconditions.checkArgument(mac.length == 6);
-
-        final StringBuilder sb = new StringBuilder(17);
-        appendByte(sb, mac[0]);
-
-        for (int i = 1; i < mac.length; i++) {
-            sb.append(':');
-            appendByte(sb, mac[i]);
-        }
-
-        return sb.toString();
-    }
-}