Merge "BUG-730: cleanup tests in pcep-impl"
authorRobert Varga <rovarga@cisco.com>
Mon, 5 May 2014 15:21:50 +0000 (15:21 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Mon, 5 May 2014 15:21:50 +0000 (15:21 +0000)
15 files changed:
bgp/linkstate-config/src/main/java/org/opendaylight/controller/config/yang/bgp/linkstate/LinkstateModule.java
bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/BGPUpdateMessageParser.java
bgp/parser-spi-config/src/main/java/org/opendaylight/controller/config/yang/bgp/parser/spi/SimpleBGPExtensionProviderContextModule.java
bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/BGPByteToMessageDecoder.java
bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/BGPSessionNegotiator.java
bgp/rib-spi-config/src/main/java/org/opendaylight/controller/config/yang/bgp/rib/spi/RIBExtensionsImplModule.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/PCEPMessageToByteEncoder.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/tlv/AbstractVendorSpecificTlvParser.java
pcep/spi-config/src/main/java/org/opendaylight/controller/config/yang/pcep/spi/SimplePCEPExtensionProviderContextModule.java
pcep/topology-provider/src/main/java/org/opendaylight/bgpcep/pcep/topology/provider/AbstractTopologySessionListener.java
programming/impl-config/src/main/java/org/opendaylight/controller/config/yang/programming/impl/InstructionSchedulerImplModule.java
tcp-md5/netty/src/main/java/org/opendaylight/bgpcep/tcpmd5/netty/MD5NioSocketChannel.java
tcp-md5/nio/src/main/java/org/opendaylight/bgpcep/tcpmd5/nio/MD5ChannelOptions.java
tcp-md5/nio/src/main/java/org/opendaylight/bgpcep/tcpmd5/nio/MD5SelectorProvider.java
util/src/main/java/org/opendaylight/protocol/util/PCEPHexDumpParser.java

index a730182f90ddcb5c4e6b04482276240765e866ec..9638e50f94062ad2ed5a9b4b3f2c2650de8031b0 100644 (file)
@@ -38,8 +38,7 @@ public final class LinkstateModule extends org.opendaylight.controller.config.ya
        }
 
        @Override
-       public void validate(){
-               super.validate();
+       public void customValidation() {
                // Add custom validation for module attributes here.
        }
 
index a1bad72479d1cfba3ea67d6e61681d904fbbfda7..05802cb6ffd0504904b78b59628bc18096041980 100644 (file)
@@ -15,6 +15,7 @@ import java.util.List;
 
 import org.opendaylight.protocol.bgp.parser.BGPDocumentedException;
 import org.opendaylight.protocol.bgp.parser.BGPError;
+import org.opendaylight.protocol.bgp.parser.BGPParsingException;
 import org.opendaylight.protocol.bgp.parser.spi.AttributeRegistry;
 import org.opendaylight.protocol.bgp.parser.spi.MessageParser;
 import org.opendaylight.protocol.concepts.Ipv4Util;
@@ -32,9 +33,9 @@ import com.google.common.base.Preconditions;
 
 /**
  * LENGTH fields, that denote the length of the fields with variable length, have fixed SIZE.
- * 
+ *
  * @see <a href="http://tools.ietf.org/html/rfc4271#section-4.3">BGP-4 Update Message Format</a>
- * 
+ *
  */
 public class BGPUpdateMessageParser implements MessageParser {
        public static final int TYPE = 2;
@@ -82,10 +83,7 @@ public class BGPUpdateMessageParser implements MessageParser {
                                final PathAttributes pathAttributes = this.reg.parseAttributes(buffer.slice(buffer.readerIndex(), totalPathAttrLength));
                                buffer.skipBytes(totalPathAttrLength);
                                eventBuilder.setPathAttributes(pathAttributes);
-                       } catch (final BGPDocumentedException e) {
-                               // Rethrow BGPDocumentedExceptions
-                               throw e;
-                       } catch (final Exception e) {
+                       } catch (final BGPParsingException | RuntimeException e) {
                                // Catch everything else and turn it into a BGPDocumentedException
                                LOG.warn("Could not parse BGP attributes", e);
                                throw new BGPDocumentedException("Could not parse BGP attributes.", BGPError.MALFORMED_ATTR_LIST, e);
index a8cb6734b6cfe5214d246dd1d6ab79b6caf04551..0a36e17f14c9b42f81b3bc32d23db032ea1964bb 100644 (file)
@@ -37,8 +37,7 @@ org.opendaylight.controller.config.yang.bgp.parser.spi.AbstractSimpleBGPExtensio
        }
 
        @Override
-       public void validate() {
-               super.validate();
+       protected void customValidation() {
                // Add custom validation for module attributes here.
        }
 
index 5b781f68d6a69de0cd8c0f33b99f1e4819e15bc6..27867d52d3cc1f95921feef0abed520625e787f1 100644 (file)
@@ -34,17 +34,12 @@ final class BGPByteToMessageDecoder extends ByteToMessageDecoder {
        }
 
        @Override
-       protected void decode(final ChannelHandlerContext ctx, final ByteBuf in, final List<Object> out) throws Exception {
-               if (in.readableBytes() == 0) {
-                       LOG.debug("No more content in incoming buffer.");
-                       return;
-               }
-               try {
+       protected void decode(final ChannelHandlerContext ctx, final ByteBuf in, final List<Object> out) throws BGPDocumentedException, BGPParsingException {
+               if (in.isReadable()) {
                        LOG.trace("Received to decode: {}", ByteBufUtil.hexDump(in));
                        out.add(this.registry.parseMessage(in));
-               } catch (BGPParsingException | BGPDocumentedException e) {
-                       LOG.debug("Failed to decode protocol message", e);
-                       this.exceptionCaught(ctx, e);
+               } else {
+                       LOG.trace("No more content in incoming buffer.");
                }
        }
 }
index e616d3c2f6cc7c6d21d3da84a823462efe18a991..d2580f525d58bff9366d98cac1a764621c968f3e 100644 (file)
@@ -47,7 +47,7 @@ public final class BGPSessionNegotiator extends AbstractSessionNegotiator<Notifi
        /**
         * @see <a href="http://tools.ietf.org/html/rfc6793">BGP Support for 4-Octet AS Number Space</a>
         */
-       private final int AS_TRANS = 23456;
+       private static final int AS_TRANS = 23456;
 
        @VisibleForTesting
        public enum State {
@@ -97,7 +97,7 @@ public final class BGPSessionNegotiator extends AbstractSessionNegotiator<Notifi
                int as = this.localPref.getMyAs().getValue().intValue();
                // Set as AS_TRANS if the value is bigger than 2B
                if (as > Values.UNSIGNED_SHORT_MAX_VALUE) {
-                       as = this.AS_TRANS;
+                       as = AS_TRANS;
                }
                this.sendMessage(new OpenBuilder().setMyAsNumber(as).setHoldTimer(
                                this.localPref.getHoldTime()).setBgpIdentifier(this.localPref.getBgpId()).setBgpParameters(this.localPref.getParams()).build());
index 71430acdb1daa718e576990cb4a2f26c1a28630d..978119852c631b785d3ac1dfd08b01e13f4ee88d 100644 (file)
@@ -36,8 +36,7 @@ public final class RIBExtensionsImplModule extends org.opendaylight.controller.c
        }
 
        @Override
-       public void validate() {
-               super.validate();
+       protected void customValidation() {
                // Add custom validation for module attributes here.
        }
 
index 83ebdf737e7406ed34e13d9407fb3de1009c71f5..84710d409d5a1a8d3484c167e4562f59c9feca90 100644 (file)
@@ -34,7 +34,7 @@ public final class PCEPMessageToByteEncoder extends MessageToByteEncoder<Message
        }
 
        @Override
-       protected void encode(final ChannelHandlerContext ctx, final Message msg, final ByteBuf out) throws Exception {
+       protected void encode(final ChannelHandlerContext ctx, final Message msg, final ByteBuf out) {
                Preconditions.checkNotNull(msg);
                this.registry.serializeMessage(msg, out);
                LOG.debug("Encoded : {}", msg);
index be0a032aa8c4e4d9f4072102a7a897053573762f..8fff0ba9975958de14273e0119d92ab45b922cca 100644 (file)
@@ -17,68 +17,68 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.typ
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.vs.tlv.VsTlvBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.vs.tlv.vs.tlv.VendorPayload;
 
-abstract public class AbstractVendorSpecificTlvParser implements TlvParser, TlvSerializer {
+public abstract class AbstractVendorSpecificTlvParser implements TlvParser, TlvSerializer {
 
-    public static final int TYPE = 27;
+       public static final int TYPE = 27;
 
-    protected static final int ENTERPRISE_NUM_LENGTH = 4;
+       protected static final int ENTERPRISE_NUM_LENGTH = 4;
 
-    @Override
-    public int getType() {
-        return TYPE;
-    }
+       @Override
+       public int getType() {
+               return TYPE;
+       }
 
-    @Override
-    public byte[] serializeTlv(Tlv tlv) {
-        if (tlv == null) {
-            throw new IllegalArgumentException("Vendor Specific Tlv is mandatory.");
-        }
-        final VsTlv vsTlv = (VsTlv) tlv;
-        if (vsTlv.getEnterpriseNumber().getValue() == getEnterpriseNumber()) {
-            final byte[] payloadBytes = serializeVendorPayload(vsTlv.getVendorPayload());
-            final byte[] ianaNumBytes = ByteArray.longToBytes(vsTlv.getEnterpriseNumber().getValue(),
-                    ENTERPRISE_NUM_LENGTH);
+       @Override
+       public byte[] serializeTlv(final Tlv tlv) {
+               if (tlv == null) {
+                       throw new IllegalArgumentException("Vendor Specific Tlv is mandatory.");
+               }
+               final VsTlv vsTlv = (VsTlv) tlv;
+               if (vsTlv.getEnterpriseNumber().getValue() == getEnterpriseNumber()) {
+                       final byte[] payloadBytes = serializeVendorPayload(vsTlv.getVendorPayload());
+                       final byte[] ianaNumBytes = ByteArray.longToBytes(vsTlv.getEnterpriseNumber().getValue(),
+                                       ENTERPRISE_NUM_LENGTH);
 
-            final byte[] bytes = new byte[ianaNumBytes.length + payloadBytes.length];
-            System.arraycopy(ianaNumBytes, 0, bytes, 0, ENTERPRISE_NUM_LENGTH);
-            System.arraycopy(payloadBytes, 0, bytes, ENTERPRISE_NUM_LENGTH, payloadBytes.length);
-            return TlvUtil.formatTlv(TYPE, bytes);
-        }
-        return new byte[0];
-    }
+                       final byte[] bytes = new byte[ianaNumBytes.length + payloadBytes.length];
+                       System.arraycopy(ianaNumBytes, 0, bytes, 0, ENTERPRISE_NUM_LENGTH);
+                       System.arraycopy(payloadBytes, 0, bytes, ENTERPRISE_NUM_LENGTH, payloadBytes.length);
+                       return TlvUtil.formatTlv(TYPE, bytes);
+               }
+               return new byte[0];
+       }
 
-    @Override
-    public VsTlv parseTlv(byte[] valueBytes) throws PCEPDeserializerException {
-        VsTlvBuilder vsTlvBuider = new VsTlvBuilder();
-        if (valueBytes == null || valueBytes.length == 0) {
-            throw new IllegalArgumentException("Array of bytes is mandatory. Can't be null or empty.");
-        }
+       @Override
+       public VsTlv parseTlv(final byte[] valueBytes) throws PCEPDeserializerException {
+               VsTlvBuilder vsTlvBuider = new VsTlvBuilder();
+               if (valueBytes == null || valueBytes.length == 0) {
+                       throw new IllegalArgumentException("Array of bytes is mandatory. Can't be null or empty.");
+               }
 
-        byte[] enBytes = ByteArray.subByte(valueBytes, 0, ENTERPRISE_NUM_LENGTH);
-        long en = ByteArray.bytesToLong(enBytes);
-        if (en == getEnterpriseNumber()) {
-            vsTlvBuider.setEnterpriseNumber(new EnterpriseNumber(getEnterpriseNumber()));
-            int byteOffset = ENTERPRISE_NUM_LENGTH;
-            int payloadLength = valueBytes.length - byteOffset;
-            VendorPayload vendorPayload = null;
-            if (payloadLength > 0) {
-                byte[] payloadBytes = ByteArray.subByte(valueBytes, byteOffset, payloadLength);
-                vendorPayload = parseVendorPayload(payloadBytes);
-                if (vendorPayload != null) {
-                    vsTlvBuider.setVendorPayload(vendorPayload);
-                }
-            }
-        }
-        return vsTlvBuider.build();
-    }
+               byte[] enBytes = ByteArray.subByte(valueBytes, 0, ENTERPRISE_NUM_LENGTH);
+               long en = ByteArray.bytesToLong(enBytes);
+               if (en == getEnterpriseNumber()) {
+                       vsTlvBuider.setEnterpriseNumber(new EnterpriseNumber(getEnterpriseNumber()));
+                       int byteOffset = ENTERPRISE_NUM_LENGTH;
+                       int payloadLength = valueBytes.length - byteOffset;
+                       VendorPayload vendorPayload = null;
+                       if (payloadLength > 0) {
+                               byte[] payloadBytes = ByteArray.subByte(valueBytes, byteOffset, payloadLength);
+                               vendorPayload = parseVendorPayload(payloadBytes);
+                               if (vendorPayload != null) {
+                                       vsTlvBuider.setVendorPayload(vendorPayload);
+                               }
+                       }
+               }
+               return vsTlvBuider.build();
+       }
 
-    abstract protected byte[] serializeVendorPayload(VendorPayload payload);
+       protected abstract byte[] serializeVendorPayload(VendorPayload payload);
 
-    abstract protected long getEnterpriseNumber();
+       protected abstract long getEnterpriseNumber();
 
-    abstract protected VendorPayload parseVendorPayload(byte[] payloadBytes) throws PCEPDeserializerException;
+       protected abstract VendorPayload parseVendorPayload(byte[] payloadBytes) throws PCEPDeserializerException;
 
-    protected static int getPadding(final int length, final int padding) {
-        return (padding - (length % padding)) % padding;
-    }
+       protected static int getPadding(final int length, final int padding) {
+               return (padding - (length % padding)) % padding;
+       }
 }
index 9a6c33f182b58370bb7b7cc91d9bad64922563ca..8531520f32f66035188445e1869a0b884bce4adb 100644 (file)
@@ -34,8 +34,7 @@ public final class SimplePCEPExtensionProviderContextModule extends org.opendayl
        }
 
        @Override
-       public void validate(){
-               super.validate();
+       protected void customValidation() {
                // Add custom validation for module attributes here.
        }
 
index b2faa1345f9bbe500237ca219fb37f8259fb3ec1..acc7e2d508f8c9717134ed2cd6b839bf9e86c113 100644 (file)
@@ -308,15 +308,20 @@ public abstract class AbstractTopologySessionListener<SRPID, PLSPID> implements
                return req.getFuture();
        }
 
-       protected final synchronized void updateLsp(final DataModificationTransaction trans, final PLSPID id, String name,
+       protected final synchronized void updateLsp(final DataModificationTransaction trans, final PLSPID id, final String lspName,
                        final ReportedLspBuilder rlb, final boolean solicited) {
-               if (name == null) {
+
+               final String name;
+               if (lspName == null) {
                        name = this.lsps.get(id);
                        if (name == null) {
                                LOG.error("PLSPID {} seen for the first time, not reporting the LSP", id);
                                return;
                        }
+               } else {
+                       name = lspName;
                }
+
                LOG.debug("Saved LSP {} with name {}", id, name);
                this.lsps.put(id, name);
 
@@ -363,9 +368,9 @@ public abstract class AbstractTopologySessionListener<SRPID, PLSPID> implements
                lspData.remove(name);
        }
 
-       abstract protected void onSessionUp(PCEPSession session, PathComputationClientBuilder pccBuilder);
+       protected abstract void onSessionUp(PCEPSession session, PathComputationClientBuilder pccBuilder);
 
-       abstract protected boolean onMessage(DataModificationTransaction trans, Message message);
+       protected abstract boolean onMessage(DataModificationTransaction trans, Message message);
 
        protected String lookupLspName(final PLSPID id) {
                Preconditions.checkNotNull(id, "ID parameter null.");
index 5c26607bc29956f1e9f7e7610ac743195ce2d009..8e28a06126ea2e8b1db81a0c20d467e70cc44504 100644 (file)
@@ -48,8 +48,7 @@ org.opendaylight.controller.config.yang.programming.impl.AbstractInstructionSche
        }
 
        @Override
-       public void validate() {
-               super.validate();
+       protected void customValidation() {
                // Add custom validation for module attributes here.
        }
 
index 2414753cdc3e1b9ba45b90fab6040b20ce9c83f9..9177eebd069009d03e973296d02ba8a2b028577d 100644 (file)
@@ -162,7 +162,7 @@ public class MD5NioSocketChannel extends AbstractNioByteChannel implements io.ne
 
        @Override
        protected void doFinishConnect() throws IOException {
-               Preconditions.checkState(javaChannel().finishConnect() == true, "finishConnect() failed");
+               Preconditions.checkState(javaChannel().finishConnect(), "finishConnect() failed");
        }
 
        @Override
index 45b656bd33f3001fe53e0fddef03dd1d9494a614..9b4bdeed44e3ec0e629c979d68fb4dfb31109387 100644 (file)
@@ -40,11 +40,10 @@ final class MD5ChannelOptions {
                return new MD5ChannelOptions(ch, access);
        }
 
+       @SuppressWarnings("unchecked")
        public <T> T getOption(final SocketOption<T> name) throws IOException {
                if (access != null && name.equals(MD5SocketOptions.TCP_MD5SIG)) {
-                       @SuppressWarnings("unchecked")
-                       final T key = (T)access.getKeys();
-                       return key;
+                       return (T)access.getKeys();
                }
 
                return ch.getOption(name);
index fa16130b223cbf384ac896b08378c9e6c97bbade..847e5bfb9c90653e8b7e55260df4d9888f20a59c 100644 (file)
@@ -35,7 +35,7 @@ public final class MD5SelectorProvider extends SelectorProvider {
                this.delegate = Preconditions.checkNotNull(delegate);
        }
 
-       public synchronized static MD5SelectorProvider getInstance(final KeyAccessFactory keyAccessFactory, final SelectorProvider provider) {
+       public static synchronized MD5SelectorProvider getInstance(final KeyAccessFactory keyAccessFactory, final SelectorProvider provider) {
                MD5SelectorProvider ret = INSTANCES.get(provider);
                if (ret == null) {
                        ret = new MD5SelectorProvider(keyAccessFactory, provider);
index fcb17e079f133420085ca523bce0e094c2cc412a..d7bd9b0429fddd60514dbfcc92b3231c8d8c8e7c 100644 (file)
@@ -25,9 +25,9 @@ import com.google.common.io.CharStreams;
 
 /**
  * Parses PCEP messages from a text file. Messages need to follow this formatting:
- * 
+ *
  * Received PCEP Open message. Length:28.
- * 
+ *
  * 20 01 00 1c 01 10 00 18 20 1e 78 03 00 10 00 04 00 00 00 05 00 1a 00 04 00 00 00 b4
  */
 public final class PCEPHexDumpParser {
@@ -76,7 +76,7 @@ public final class PCEPHexDumpParser {
                        try {
                                message = Hex.decodeHex(hexMessage.toCharArray());
                        } catch (final DecoderException e) {
-                               new RuntimeException(e);
+                               new IllegalArgumentException("Failed to decode message", e);
                        }
                        messages.add(message);
                        idx = messageEndIdx;