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)
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 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();
-    }
-}