BUG-49 : removed various PMD warnings. 55/2055/2
authorDana Kutenicsova <dkutenic@cisco.com>
Mon, 21 Oct 2013 16:13:01 +0000 (18:13 +0200)
committerDana Kutenicsova <dkutenic@cisco.com>
Tue, 22 Oct 2013 12:09:47 +0000 (14:09 +0200)
Change-Id: I6b10eb52e0d0a3500436490451ea4673793aac0c
Signed-off-by: Dana Kutenicsova <dkutenic@cisco.com>
27 files changed:
bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/LinkstateAttributeParser.java
bgp/parser-api/src/main/java/org/opendaylight/protocol/bgp/parser/BGPDocumentedException.java
bgp/parser-api/src/main/java/org/opendaylight/protocol/bgp/parser/BGPError.java
bgp/parser-api/src/main/java/org/opendaylight/protocol/bgp/parser/BgpTableTypeImpl.java
bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/Activator.java
bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/open/GracefulCapabilityHandler.java
bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/AsPathSegmentParser.java
bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/CommunitiesParser.java
bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/CommunityUtil.java [moved from bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/CommunityUtil.java with 96% similarity]
bgp/parser-impl/src/test/java/org/opendaylight/protocol/bgp/parser/impl/BGPParserTest.java
bgp/parser-impl/src/test/java/org/opendaylight/protocol/bgp/parser/impl/CommunityTest.java
bgp/parser-spi/src/main/java/org/opendaylight/protocol/bgp/parser/spi/NlriRegistry.java
bgp/parser-spi/src/main/java/org/opendaylight/protocol/bgp/parser/spi/pojo/AbstractMessageRegistry.java
bgp/parser-spi/src/main/java/org/opendaylight/protocol/bgp/parser/spi/pojo/SimpleBGPExtensionConsumerContext.java
bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/Activator.java
bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/BGPMessageHeaderDecoder.java
bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/BGPObjectComparator.java
bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/BGPSessionImpl.java
bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/BGPSessionNegotiator.java
bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/BGPSessionProposalImpl.java
bgp/rib-mock/src/main/java/org/opendaylight/protocol/bgp/rib/mock/BGPMock.java
bgp/rib-mock/src/main/java/org/opendaylight/protocol/bgp/rib/mock/EventBusRegistration.java
bgp/rib-spi/src/main/java/org/opendaylight/protocol/bgp/rib/spi/AbstractAdjRIBsIn.java
bgp/testtool/src/main/java/org/opendaylight/protocol/bgp/testtool/Main.java
bgp/util/src/main/java/org/opendaylight/protocol/bgp/util/BinaryBGPDumpFileParser.java
bgp/util/src/main/java/org/opendaylight/protocol/bgp/util/HexDumpBGPFileParser.java
bgp/util/src/test/java/org/opendaylight/protocol/bgp/util/BGPHexFileParserTest.java

index 62dee6e7c1ba3dfa1e9f6e0e4c56a42b8e3d9840..767dd9da0eba0f86a0f8fc17b0a53ae305e09732 100644 (file)
@@ -125,7 +125,7 @@ public class LinkstateAttributeParser implements AttributeParser {
                        final int length = ByteArray.bytesToInt(ByteArray.subByte(bytes, byteOffset, LENGTH_SIZE));
                        byteOffset += LENGTH_SIZE;
                        final byte[] value = ByteArray.subByte(bytes, byteOffset, length);
-                       ByteList values = map.containsKey(type) ? values = map.get(type) : new ByteList();
+                       final ByteList values = map.containsKey(type) ? map.get(type) : new ByteList();
                        values.add(value);
                        map.put(type, values);
                        byteOffset += length;
index 7b1c69771be1a45b474406dc95ef8923b49fcedf..ad1fba76e7413bff3d4f66146e3c26ee2786d5c5 100644 (file)
@@ -45,7 +45,7 @@ public final class BGPDocumentedException extends DocumentedException {
         * @param error specific documented error
         * @param cause cause for the error
         */
-       public BGPDocumentedException(final String message, final BGPError error, final Throwable cause) {
+       public BGPDocumentedException(final String message, final BGPError error, final Exception cause) {
                this(message, error, null, cause);
        }
 
@@ -68,8 +68,8 @@ public final class BGPDocumentedException extends DocumentedException {
         * @param data data associated with the error
         * @param cause cause for the error
         */
-       public BGPDocumentedException(final String message, final BGPError error, final byte[] data, final Throwable cause) {
-               super(message);
+       public BGPDocumentedException(final String message, final BGPError error, final byte[] data, final Exception cause) {
+               super(message, cause);
                this.error = error;
                this.data = data;
                logger.error("Error = " + error, this);
@@ -96,8 +96,8 @@ public final class BGPDocumentedException extends DocumentedException {
        public static BGPDocumentedException badMessageLength(final String message, final int length) {
                Preconditions.checkArgument(length >= 0 && length <= 65535);
 
-               return new BGPDocumentedException(message, BGPError.BAD_MSG_LENGTH, new byte[] {
-                               UnsignedBytes.checkedCast(length / 256), UnsignedBytes.checkedCast(length % 256) });
+               return new BGPDocumentedException(message, BGPError.BAD_MSG_LENGTH, new byte[] { UnsignedBytes.checkedCast(length / 256),
+                               UnsignedBytes.checkedCast(length % 256) });
 
        }
 }
index b08b25e878f33595f7210ddf641bb49d8eeff8a5..60d090362b8d9f88eaf1f76b579ad992cf13550b 100644 (file)
@@ -122,52 +122,72 @@ public enum BGPError {
 
        public static BGPError forValue(final int e, final int s) {
                if (e == 1) {
-                       if (s == 1)
+                       if (s == 1) {
                                return BGPError.CONNECTION_NOT_SYNC;
-                       if (s == 2)
+                       }
+                       if (s == 2) {
                                return BGPError.BAD_MSG_LENGTH;
-                       if (s == 3)
+                       }
+                       if (s == 3) {
                                return BGPError.BAD_MSG_TYPE;
+                       }
                } else if (e == 2) {
-                       if (s == 0)
+                       if (s == 0) {
                                return BGPError.UNSPECIFIC_OPEN_ERROR;
-                       if (s == 1)
+                       }
+                       if (s == 1) {
                                return BGPError.VERSION_NOT_SUPPORTED;
-                       if (s == 2)
+                       }
+                       if (s == 2) {
                                return BGPError.BAD_PEER_AS;
-                       if (s == 3)
+                       }
+                       if (s == 3) {
                                return BGPError.BAD_BGP_ID;
-                       if (s == 4)
+                       }
+                       if (s == 4) {
                                return BGPError.OPT_PARAM_NOT_SUPPORTED;
-                       if (s == 6)
+                       }
+                       if (s == 6) {
                                return BGPError.HOLD_TIME_NOT_ACC;
+                       }
                } else if (e == 3) {
-                       if (s == 1)
+                       if (s == 1) {
                                return BGPError.MALFORMED_ATTR_LIST;
-                       if (s == 2)
+                       }
+                       if (s == 2) {
                                return BGPError.WELL_KNOWN_ATTR_NOT_RECOGNIZED;
-                       if (s == 3)
+                       }
+                       if (s == 3) {
                                return BGPError.WELL_KNOWN_ATTR_MISSING;
-                       if (s == 4)
+                       }
+                       if (s == 4) {
                                return BGPError.ATTR_FLAGS_MISSING;
-                       if (s == 5)
+                       }
+                       if (s == 5) {
                                return BGPError.ATTR_LENGTH_ERROR;
-                       if (s == 6)
+                       }
+                       if (s == 6) {
                                return BGPError.ORIGIN_ATTR_NOT_VALID;
-                       if (s == 8)
+                       }
+                       if (s == 8) {
                                return BGPError.NEXT_HOP_NOT_VALID;
-                       if (s == 9)
+                       }
+                       if (s == 9) {
                                return BGPError.OPT_ATTR_ERROR;
-                       if (s == 10)
+                       }
+                       if (s == 10) {
                                return BGPError.NETWORK_NOT_VALID;
-                       if (s == 11)
+                       }
+                       if (s == 11) {
                                return BGPError.AS_PATH_MALFORMED;
-               } else if (e == 4)
+                       }
+               } else if (e == 4) {
                        return BGPError.HOLD_TIMER_EXPIRED;
-               else if (e == 5)
+               } else if (e == 5) {
                        return BGPError.FSM_ERROR;
-               else if (e == 6)
+               } else if (e == 6) {
                        return BGPError.CEASE;
+               }
                throw new IllegalArgumentException("BGP Error code " + e + " and subcode " + s + " not recognized.");
        }
 }
index 03763d5464233832881e8a4602926f7994f768df..1e6b430447cdb23196b04754e33f161d43c3fea0 100644 (file)
@@ -47,7 +47,7 @@ public final class BgpTableTypeImpl implements BgpTableType {
 
        @Override
        public boolean equals(final Object obj) {
-               if (obj != null && obj instanceof BgpTableTypeImpl) {
+               if (obj instanceof BgpTableTypeImpl) {
                        final BgpTableTypeImpl o = (BgpTableTypeImpl) obj;
                        return this.afi.equals(o.afi) && this.safi.equals(o.safi);
                }
index 82162a9130866c6d7d336bf60c29dbc53f74c5a6..077a3fe7105c46febc157d984b3e6d01ae096a02 100644 (file)
@@ -63,7 +63,7 @@ public final class Activator implements BGPExtensionProviderActivator {
 
        @Override
        public synchronized void start(final BGPExtensionProviderContext context) {
-               Preconditions.checkState(registrations == null);
+               Preconditions.checkState(this.registrations == null);
                final List<AutoCloseable> regs = new ArrayList<>();
 
                final AddressFamilyRegistry afiReg = context.getAddressFamilyRegistry();
@@ -75,17 +75,14 @@ public final class Activator implements BGPExtensionProviderActivator {
                regs.add(context.registerSubsequentAddressFamily(MplsLabeledVpnSubsequentAddressFamily.class, 128));
 
                final NlriRegistry nlriReg = context.getNlriRegistry();
-               regs.add(context.registerNlriParser(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class,
-                               new Ipv4NlriParser()));
-               regs.add(context.registerNlriParser(Ipv6AddressFamily.class, UnicastSubsequentAddressFamily.class,
-                               new Ipv6NlriParser()));
+               regs.add(context.registerNlriParser(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class, new Ipv4NlriParser()));
+               regs.add(context.registerNlriParser(Ipv6AddressFamily.class, UnicastSubsequentAddressFamily.class, new Ipv6NlriParser()));
 
                final AttributeRegistry attrReg = context.getAttributeRegistry();
                regs.add(context.registerAttributeParser(OriginAttributeParser.TYPE, new OriginAttributeParser()));
                regs.add(context.registerAttributeParser(AsPathAttributeParser.TYPE, new AsPathAttributeParser()));
                regs.add(context.registerAttributeParser(NextHopAttributeParser.TYPE, new NextHopAttributeParser()));
-               regs.add(context.registerAttributeParser(MultiExitDiscriminatorAttributeParser.TYPE,
-                               new MultiExitDiscriminatorAttributeParser()));
+               regs.add(context.registerAttributeParser(MultiExitDiscriminatorAttributeParser.TYPE, new MultiExitDiscriminatorAttributeParser()));
                regs.add(context.registerAttributeParser(LocalPreferenceAttributeParser.TYPE, new LocalPreferenceAttributeParser()));
                regs.add(context.registerAttributeParser(AtomicAggregateAttributeParser.TYPE, new AtomicAggregateAttributeParser()));
                regs.add(context.registerAttributeParser(AggregatorAttributeParser.TYPE, new AggregatorAttributeParser()));
@@ -119,7 +116,6 @@ public final class Activator implements BGPExtensionProviderActivator {
                final BGPUpdateMessageParser ump = new BGPUpdateMessageParser(attrReg);
                regs.add(context.registerMessageParser(BGPUpdateMessageParser.TYPE, ump));
                // Serialization of Update message is not supported
-               // regs.add(msgReg.registerMessageSerializer(Update.class, ump));
 
                final BGPNotificationMessageParser nmp = new BGPNotificationMessageParser();
                regs.add(context.registerMessageParser(BGPNotificationMessageParser.TYPE, nmp));
@@ -129,21 +125,21 @@ public final class Activator implements BGPExtensionProviderActivator {
                regs.add(context.registerMessageParser(BGPKeepAliveMessageParser.TYPE, kamp));
                regs.add(context.registerMessageSerializer(Keepalive.class, kamp));
 
-               registrations = regs;
+               this.registrations = regs;
        }
 
        @Override
        public synchronized void stop() {
-               Preconditions.checkState(registrations != null);
+               Preconditions.checkState(this.registrations != null);
 
-               for (AutoCloseable r : registrations) {
+               for (final AutoCloseable r : this.registrations) {
                        try {
                                r.close();
-                       } catch (Exception e) {
+                       } catch (final Exception e) {
                                logger.warn("Failed to close registration", e);
                        }
                }
 
-               registrations = null;
+               this.registrations = null;
        }
 }
index d1c16ce30c45fd1818821130362b25f16be0fbbd..50073f29eff5dee5f6cb3884874148dd06806d4f 100644 (file)
@@ -25,7 +25,8 @@ final class GracefulCapabilityHandler implements CapabilitySerializer {
                final byte[] bytes = null;
 
                // final GracefulCapability param = (GracefulCapability) capability;
-               // final byte[] bytes = new byte[(RESTART_FLAGS_SIZE + TIMER_SIZE + (AFI_SIZE * Byte.SIZE + SAFI_SIZE * Byte.SIZE +
+               // final byte[] bytes = new byte[(RESTART_FLAGS_SIZE + TIMER_SIZE + (AFI_SIZE * Byte.SIZE + SAFI_SIZE *
+               // Byte.SIZE +
                // AF_FLAGS_SIZE
                // * Byte.SIZE)
                // * param.getTableTypes().size())
index 1007e3e75fd26c8cd40cde0ee60709865e6a4501..bfdc12950fc735d167858c3ab3110645513dbc8f 100644 (file)
@@ -23,7 +23,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.type
  * the collection is a Set.
  * 
  */
-public class AsPathSegmentParser {
+public final class AsPathSegmentParser {
 
        public static final int TYPE_LENGTH = 1; // bytes
 
index 999038d96fa0014bc87e282fc698801b92cbf543..26a97a7ae069e3619d8ead661952a60b59cc923a 100644 (file)
@@ -12,7 +12,6 @@ import java.util.Arrays;
 
 import org.opendaylight.protocol.bgp.parser.BGPDocumentedException;
 import org.opendaylight.protocol.bgp.parser.BGPError;
-import org.opendaylight.protocol.bgp.parser.impl.CommunityUtil;
 import org.opendaylight.protocol.concepts.Ipv4Util;
 import org.opendaylight.protocol.util.ByteArray;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.AsNumber;
@@ -35,7 +34,7 @@ import com.google.common.primitives.UnsignedBytes;
 /**
  * Parser for Extended Communities Path Attribute.
  */
-public class CommunitiesParser {
+public final class CommunitiesParser {
 
        public static final int EXTENDED_COMMUNITY_LENGTH = 8; // bytes
 
@@ -92,34 +91,34 @@ public class CommunitiesParser {
                                return new CRouteTargetExtendedCommunityBuilder().setRouteTargetExtendedCommunity(
                                                new RouteTargetExtendedCommunityBuilder().setGlobalAdministrator(
                                                                new AsNumber(ByteArray.bytesToLong(ByteArray.subByte(value, 0, AS_NUMBER_LENGTH)))).setLocalAdministrator(
-                                                                               ByteArray.subByte(value, AS_NUMBER_LENGTH, AS_LOCAL_ADMIN_LENGTH)).build()).build();
+                                                               ByteArray.subByte(value, AS_NUMBER_LENGTH, AS_LOCAL_ADMIN_LENGTH)).build()).build();
                        } else if (subType == 3) {
                                return new CRouteOriginExtendedCommunityBuilder().setRouteOriginExtendedCommunity(
                                                new RouteOriginExtendedCommunityBuilder().setGlobalAdministrator(
                                                                new AsNumber(ByteArray.bytesToLong(ByteArray.subByte(value, 0, AS_NUMBER_LENGTH)))).setLocalAdministrator(
-                                                                               ByteArray.subByte(value, AS_NUMBER_LENGTH, AS_LOCAL_ADMIN_LENGTH)).build()).build();
+                                                               ByteArray.subByte(value, AS_NUMBER_LENGTH, AS_LOCAL_ADMIN_LENGTH)).build()).build();
                        } else {
                                return new CAsSpecificExtendedCommunityBuilder().setAsSpecificExtendedCommunity(
                                                new AsSpecificExtendedCommunityBuilder().setTransitive(false).setGlobalAdministrator(
                                                                new AsNumber(ByteArray.bytesToLong(ByteArray.subByte(value, 0, AS_NUMBER_LENGTH)))).setLocalAdministrator(
-                                                                               ByteArray.subByte(value, AS_NUMBER_LENGTH, AS_LOCAL_ADMIN_LENGTH)).build()).build();
+                                                               ByteArray.subByte(value, AS_NUMBER_LENGTH, AS_LOCAL_ADMIN_LENGTH)).build()).build();
                        }
                case 40: // 01000000
                        return new CAsSpecificExtendedCommunityBuilder().setAsSpecificExtendedCommunity(
                                        new AsSpecificExtendedCommunityBuilder().setTransitive(true).setGlobalAdministrator(
                                                        new AsNumber(ByteArray.bytesToLong(ByteArray.subByte(value, 0, AS_NUMBER_LENGTH)))).setLocalAdministrator(
-                                                                       ByteArray.subByte(value, AS_NUMBER_LENGTH, AS_LOCAL_ADMIN_LENGTH)).build()).build();
+                                                       ByteArray.subByte(value, AS_NUMBER_LENGTH, AS_LOCAL_ADMIN_LENGTH)).build()).build();
                case 2:
                        if (subType == 2) {
                                return new CRouteTargetExtendedCommunityBuilder().setRouteTargetExtendedCommunity(
                                                new RouteTargetExtendedCommunityBuilder().setGlobalAdministrator(
                                                                new AsNumber(ByteArray.bytesToLong(ByteArray.subByte(value, 0, AS_NUMBER_LENGTH)))).setLocalAdministrator(
-                                                                               ByteArray.subByte(value, AS_NUMBER_LENGTH, AS_LOCAL_ADMIN_LENGTH)).build()).build();
+                                                               ByteArray.subByte(value, AS_NUMBER_LENGTH, AS_LOCAL_ADMIN_LENGTH)).build()).build();
                        } else if (subType == 3) {
                                return new CRouteOriginExtendedCommunityBuilder().setRouteOriginExtendedCommunity(
                                                new RouteOriginExtendedCommunityBuilder().setGlobalAdministrator(
                                                                new AsNumber(ByteArray.bytesToLong(ByteArray.subByte(value, 0, AS_NUMBER_LENGTH)))).setLocalAdministrator(
-                                                                               ByteArray.subByte(value, AS_NUMBER_LENGTH, AS_LOCAL_ADMIN_LENGTH)).build()).build();
+                                                               ByteArray.subByte(value, AS_NUMBER_LENGTH, AS_LOCAL_ADMIN_LENGTH)).build()).build();
                        } else {
                                throw new BGPDocumentedException("Could not parse Extended Community subtype: " + subType, BGPError.OPT_ATTR_ERROR);
                        }
@@ -128,17 +127,17 @@ public class CommunitiesParser {
                                return new CRouteTargetExtendedCommunityBuilder().setRouteTargetExtendedCommunity(
                                                new RouteTargetExtendedCommunityBuilder().setGlobalAdministrator(
                                                                new AsNumber(ByteArray.bytesToLong(ByteArray.subByte(value, 0, AS_NUMBER_LENGTH)))).setLocalAdministrator(
-                                                                               ByteArray.subByte(value, AS_NUMBER_LENGTH, AS_LOCAL_ADMIN_LENGTH)).build()).build();
+                                                               ByteArray.subByte(value, AS_NUMBER_LENGTH, AS_LOCAL_ADMIN_LENGTH)).build()).build();
                        } else if (subType == 3) {
                                return new CRouteOriginExtendedCommunityBuilder().setRouteOriginExtendedCommunity(
                                                new RouteOriginExtendedCommunityBuilder().setGlobalAdministrator(
                                                                new AsNumber(ByteArray.bytesToLong(ByteArray.subByte(value, 0, AS_NUMBER_LENGTH)))).setLocalAdministrator(
-                                                                               ByteArray.subByte(value, AS_NUMBER_LENGTH, AS_LOCAL_ADMIN_LENGTH)).build()).build();
+                                                               ByteArray.subByte(value, AS_NUMBER_LENGTH, AS_LOCAL_ADMIN_LENGTH)).build()).build();
                        } else {
                                return new CInet4SpecificExtendedCommunityBuilder().setInet4SpecificExtendedCommunity(
                                                new Inet4SpecificExtendedCommunityBuilder().setTransitive(false).setGlobalAdministrator(
                                                                Ipv4Util.addressForBytes(ByteArray.subByte(value, 0, 4))).setLocalAdministrator(
-                                                                               ByteArray.subByte(value, 4, 2)).build()).build();
+                                                               ByteArray.subByte(value, 4, 2)).build()).build();
                        }
                case 41: // 01000001
                        return new CInet4SpecificExtendedCommunityBuilder().setInet4SpecificExtendedCommunity(
similarity index 96%
rename from bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/CommunityUtil.java
rename to bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/CommunityUtil.java
index 393862b65baa865eacfc7b6aae0776e28d659f68..c312b7a831e1d14fb2614cfba49cd6df251e6293 100644 (file)
@@ -5,7 +5,7 @@
  * 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.protocol.bgp.parser.impl;
+package org.opendaylight.protocol.bgp.parser.impl.message.update;
 
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.AsNumber;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.path.attributes.CommunitiesBuilder;
@@ -34,6 +34,10 @@ public final class CommunityUtil {
         */
        public static final Community NO_EXPORT_SUBCONFED = CommunityUtil.create(0xFFFF, 0xFF03);
 
+       private CommunityUtil() {
+
+       }
+
        /**
         * Creates a new Community given AS number value and semantics using generated CommunitiesBuilder.
         * 
index a17d4faf653fa0bea71a5a7691c127081ced38b4..c4a237fcae6e47d3e84b12b3de632d8f1fd02151 100644 (file)
@@ -24,6 +24,7 @@ import org.junit.Ignore;
 import org.junit.Test;
 import org.opendaylight.protocol.bgp.parser.BgpTableTypeImpl;
 import org.opendaylight.protocol.bgp.parser.impl.message.BGPUpdateMessageParser;
+import org.opendaylight.protocol.bgp.parser.impl.message.update.CommunityUtil;
 import org.opendaylight.protocol.bgp.parser.spi.MessageRegistry;
 import org.opendaylight.protocol.bgp.parser.spi.MessageUtil;
 import org.opendaylight.protocol.bgp.parser.spi.pojo.ServiceLoaderBGPExtensionProviderContext;
index 94021ad5552d3df5a5d8871bc763372bdabdb069..3512abf39aeb7f9f3c94f65942929956ce4efad5 100644 (file)
@@ -13,6 +13,7 @@ import static org.junit.Assert.fail;
 
 import org.junit.Ignore;
 import org.junit.Test;
+import org.opendaylight.protocol.bgp.parser.impl.message.update.CommunityUtil;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Community;
 
 public class CommunityTest {
index d6d7f0bc76244c51a3501e1b6d22f11ce1871611..f8218e4a07751c0f891c14eed368617bac950b6a 100644 (file)
@@ -13,6 +13,8 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.mult
 
 public interface NlriRegistry {
        public MpUnreachNlri parseMpUnreach(final byte[] bytes) throws BGPParsingException;
+
        public MpReachNlri parseMpReach(final byte[] bytes) throws BGPParsingException;
-       //      public byte[] serializeNlri(DataObject attribute);
+       // FIXME: PMD remove or put a comment what is this
+       // public byte[] serializeNlri(DataObject attribute);
 }
index a1c4ed2c870f9635fe5507086b770a5db34c6cf1..6b6f0e7fc2ddaf99967aaebb9dbae70f06e3d22b 100644 (file)
@@ -25,6 +25,7 @@ abstract class AbstractMessageRegistry implements MessageRegistry {
        private final static Logger logger = LoggerFactory.getLogger(AbstractMessageRegistry.class);
 
        protected abstract Notification parseBody(final int type, final byte[] body, final int messageLength) throws BGPDocumentedException;
+
        protected abstract byte[] serializeMessageImpl(final Notification message);
 
        @Override
@@ -36,13 +37,13 @@ abstract class AbstractMessageRegistry implements MessageRegistry {
                        throw new IllegalArgumentException("Too few bytes in passed array. Passed: " + bytes.length + ". Expected: >= "
                                        + MessageUtil.COMMON_HEADER_LENGTH + ".");
                }
-               /*
-                * byte array starts with message length
-                */
-               // final byte[] ones = new byte[MARKER_LENGTH];
-               // Arrays.fill(ones, (byte)0xff);
-               // if (Arrays.equals(bytes, ones))
+               final byte[] marker = ByteArray.subByte(bytes, 0, MessageUtil.MARKER_LENGTH);
+               final byte[] ones = new byte[MessageUtil.MARKER_LENGTH];
+               Arrays.fill(ones, (byte) 0xff);
+               // TODO: possible refactor
+               // if (Arrays.equals(marker, ones)) {
                // throw new BGPDocumentedException("Marker not set to ones.", BGPError.CONNECTION_NOT_SYNC);
+               // }
                final byte[] bs = ByteArray.cutBytes(bytes, MessageUtil.MARKER_LENGTH);
                final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(bs, 0, MessageUtil.LENGTH_FIELD_LENGTH));
                final int messageType = UnsignedBytes.toInt(bs[MessageUtil.LENGTH_FIELD_LENGTH]);
index 58288c37f58fb858089bb1b40ec4358325d4695a..5db9db44a6d5769b9a12b4c4dab42c6210c4f9df 100644 (file)
@@ -23,40 +23,40 @@ class SimpleBGPExtensionConsumerContext implements BGPExtensionConsumerContext {
        protected final SimpleMessageRegistry msgReg = new SimpleMessageRegistry();
        protected final SimpleSubsequentAddressFamilyRegistry safiReg = new SimpleSubsequentAddressFamilyRegistry();
        protected final SimpleParameterRegistry paramReg = new SimpleParameterRegistry();
-       protected final SimpleNlriRegistry nlriReg = new SimpleNlriRegistry(afiReg, safiReg);
+       protected final SimpleNlriRegistry nlriReg = new SimpleNlriRegistry(this.afiReg, this.safiReg);
 
        @Override
        public final AddressFamilyRegistry getAddressFamilyRegistry() {
-               return afiReg;
+               return this.afiReg;
        }
 
        @Override
        public final AttributeRegistry getAttributeRegistry() {
-               return attrReg;
+               return this.attrReg;
        }
 
        @Override
        public final CapabilityRegistry getCapabilityRegistry() {
-               return capReg;
+               return this.capReg;
        }
 
        @Override
        public final MessageRegistry getMessageRegistry() {
-               return msgReg;
+               return this.msgReg;
        }
 
        @Override
        public final NlriRegistry getNlriRegistry() {
-               return nlriReg;
+               return this.nlriReg;
        }
 
        @Override
        public final ParameterRegistry getParameterRegistry() {
-               return paramReg;
+               return this.paramReg;
        }
 
        @Override
        public final SubsequentAddressFamilyRegistry getSubsequentAddressFamilyRegistry() {
-               return safiReg;
+               return this.safiReg;
        }
 }
index 3c87f8ed5bc9402b5f9bd3b58acb0e7825d00de1..c62c9172ca99344ccf49797eddff0c05b6b629c5 100644 (file)
@@ -1,16 +1,15 @@
 package org.opendaylight.protocol.bgp.rib.impl;
 
 import org.opendaylight.controller.sal.binding.api.AbstractBindingAwareProvider;
-import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ConsumerContext;
 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
 import org.opendaylight.controller.sal.binding.api.data.DataProviderService;
 
 public final class Activator extends AbstractBindingAwareProvider {
+       @SuppressWarnings("unused")
        private RIBImpl rib;
 
-
        @Override
        public void onSessionInitiated(final ProviderContext session) {
-               rib = new RIBImpl(session.getSALService(DataProviderService.class));
+               this.rib = new RIBImpl(session.getSALService(DataProviderService.class));
        }
 }
index e4144ba9ef308f6955958d7b8d3e5a2dc66913fb..dd65579f625dfeb291f5704de73eef02a143a6ad 100644 (file)
@@ -27,11 +27,11 @@ public final class BGPMessageHeaderDecoder extends LengthFieldBasedFrameDecoder
          0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
          +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
          |                                                               |
-         +                                                               +
          |                                                               |
-         +                                                               +
+         |                                                               |
+         |                                                               |
          |                           Marker                              |
-         +                                                               +
+         |                                                               |
          |                                                               |
          +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
          |          Length               |      Type     |
index 33fcf0e2614027168ce5258a6aa736ec7f12be38..767009bfecb2214597a3addf4d4e8f0c3dd727cf 100644 (file)
@@ -11,7 +11,6 @@ import java.util.Comparator;
 
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.PathAttributes;
 
-
 /**
  * This comparator is intended to implement BGP Best Path Selection algorithm, as described at
  * 
@@ -27,15 +26,15 @@ final class BGPObjectComparator implements Comparator<PathAttributes> {
 
        @Override
        public int compare(final PathAttributes o1, final PathAttributes o2) {
-               if (o1 == o2) {
-                       return 0;
-               }
                if (o1 == null) {
                        return 1;
                }
                if (o2 == null) {
                        return -1;
                }
+               if (o1.equals(o2)) {
+                       return 0;
+               }
 
                // FIXME: look at ASPath
                // FIXME: look at everything else :-)
index 4824a52c09fa4d970bf51729d30abc18911c0b4a..9dd80cf7ce24d583f8ca5cd1dd27369aabd370a7 100644 (file)
@@ -53,7 +53,7 @@ public class BGPSessionImpl extends AbstractProtocolSession<Notification> implem
 
        private static final Notification keepalive = new KeepaliveBuilder().build();
 
-       public static int HOLD_TIMER_VALUE = DEFAULT_HOLD_TIMER_VALUE; // 240
+       private static int holdTimerValue = DEFAULT_HOLD_TIMER_VALUE; // 240
 
        /**
         * Internal session state.
@@ -78,6 +78,7 @@ public class BGPSessionImpl extends AbstractProtocolSession<Notification> implem
        /**
         * System.nanoTime value about when was sent the last message Protected to be updated also in tests.
         */
+       @VisibleForTesting
        protected long lastMessageSentAt;
 
        /**
@@ -110,6 +111,7 @@ public class BGPSessionImpl extends AbstractProtocolSession<Notification> implem
                this.stateTimer = Preconditions.checkNotNull(timer);
                this.channel = Preconditions.checkNotNull(channel);
                this.keepAlive = remoteOpen.getHoldTimer() / 3;
+               holdTimerValue = remoteOpen.getHoldTimer();
 
                final Set<BgpTableType> tts = Sets.newHashSet();
                if (remoteOpen.getBgpParameters() != null) {
@@ -234,7 +236,7 @@ public class BGPSessionImpl extends AbstractProtocolSession<Notification> implem
                }
 
                final long ct = System.nanoTime();
-               final long nextHold = this.lastMessageReceivedAt + TimeUnit.SECONDS.toNanos(HOLD_TIMER_VALUE);
+               final long nextHold = this.lastMessageReceivedAt + TimeUnit.SECONDS.toNanos(holdTimerValue);
 
                if (ct >= nextHold) {
                        logger.debug("HoldTimer expired. " + new Date());
index c837d15a25b0f22a400b7f1d1f35d4d0bc88b369..e849e19e139b56acf980c8280adf20351a27f1f6 100644 (file)
@@ -119,9 +119,9 @@ public final class BGPSessionNegotiator extends AbstractSessionNegotiator<Notifi
                switch (this.state) {
                case Finished:
                case Idle:
-                       final Notify fsm_error = new NotifyBuilder().setErrorCode(BGPError.FSM_ERROR.getCode()).setErrorSubcode(
+                       final Notify fsmError = new NotifyBuilder().setErrorCode(BGPError.FSM_ERROR.getCode()).setErrorSubcode(
                                        BGPError.FSM_ERROR.getSubcode()).build();
-                       this.channel.writeAndFlush(fsm_error);
+                       this.channel.writeAndFlush(fsmError);
                case OpenConfirm:
                        if (msg instanceof Keepalive) {
                                negotiationSuccessful(this.session);
index ca1a8ff513c3c864d48d3b2b5efdde06b1c6954f..0140ebe58e1a332be0c1c043754e1de0bc0309b2 100644 (file)
@@ -16,6 +16,7 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.LinkstateAddressFamily;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.LinkstateSubsequentAddressFamily;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.open.BgpParameters;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.open.BgpParametersBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.open.bgp.parameters.c.parameters.CAs4BytesBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.open.bgp.parameters.c.parameters.c.as4.bytes.As4BytesCapabilityBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.open.bgp.parameters.c.parameters.CMultiprotocolBuilder;
@@ -44,16 +45,19 @@ public final class BGPSessionProposalImpl implements BGPSessionProposal {
                this.bgpId = bgpId;
 
                final List<BgpParameters> tlvs = Lists.newArrayList();
-               tlvs.add((BgpParameters) new CMultiprotocolBuilder().setMultiprotocolCapability(new MultiprotocolCapabilityBuilder().setAfi(
-                               Ipv4AddressFamily.class).setSafi(UnicastSubsequentAddressFamily.class).build()));
-               tlvs.add((BgpParameters) new CMultiprotocolBuilder().setMultiprotocolCapability(new MultiprotocolCapabilityBuilder().setAfi(
-                               LinkstateAddressFamily.class).setSafi(LinkstateSubsequentAddressFamily.class).build()));
+               tlvs.add(new BgpParametersBuilder().setCParameters(
+                               new CMultiprotocolBuilder().setMultiprotocolCapability(
+                                               new MultiprotocolCapabilityBuilder().setAfi(Ipv4AddressFamily.class).setSafi(UnicastSubsequentAddressFamily.class).build()).build()).build());
+               tlvs.add(new BgpParametersBuilder().setCParameters(
+                               new CMultiprotocolBuilder().setMultiprotocolCapability(
+                                               new MultiprotocolCapabilityBuilder().setAfi(LinkstateAddressFamily.class).setSafi(
+                                                               LinkstateSubsequentAddressFamily.class).build()).build()).build());
                // final Map<BGPTableType, Boolean> tableTypes = Maps.newHashMap();
                // tableTypes.put(ipv4, true);
                // tableTypes.put(linkstate,true);
                // tlvs.add(new GracefulCapability(true, 0, tableTypes));
-               tlvs.add((BgpParameters) new CAs4BytesBuilder().setAs4BytesCapability(new As4BytesCapabilityBuilder().setAsNumber(
-                               new AsNumber((long) as)).build()));
+               tlvs.add(new BgpParametersBuilder().setCParameters(
+                               new CAs4BytesBuilder().setAs4BytesCapability(new As4BytesCapabilityBuilder().setAsNumber(new AsNumber((long) as)).build()).build()).build());
                this.prefs = new BGPSessionPreferences(as, holdTimer, bgpId, tlvs);
        }
 
index 4889114acc69b6a86594a4bbb8a326fdecdc9437..cb5bf7f8da371693977ae402d2dac8f0a961445b 100644 (file)
@@ -28,6 +28,8 @@ import org.opendaylight.protocol.framework.ReconnectStrategy;
 import org.opendaylight.protocol.util.ByteArray;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.NotifyBuilder;
 import org.opendaylight.yangtools.yang.binding.Notification;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import com.google.common.collect.Lists;
 import com.google.common.eventbus.EventBus;
@@ -39,6 +41,9 @@ import com.google.common.eventbus.EventBus;
  */
 @ThreadSafe
 public final class BGPMock implements BGP, Closeable {
+
+       private final static Logger logger = LoggerFactory.getLogger(BGPMock.class);
+
        static final Notification connectionLostMagicMessage = new NotifyBuilder().setErrorCode(BGPError.CEASE.getCode()).build();
 
        @GuardedBy("this")
@@ -66,9 +71,9 @@ public final class BGPMock implements BGP, Closeable {
                                messages.add(parser.parse(body));
                        }
                } catch (final DeserializerException e) {
-                       e.printStackTrace();
+                       logger.warn(e.getMessage(), e);
                } catch (final DocumentedException e) {
-                       e.printStackTrace();
+                       logger.warn(e.getMessage(), e);
                }
                return messages;
        }
index 62aefcecd54449fbf9399849546da9a2a7f74273..814c6c2c38725414cda85e32c2ddcb83fa3000f9 100644 (file)
@@ -30,7 +30,7 @@ import com.google.common.eventbus.Subscribe;
  * This class has @Subscribe annotated methods which receive events from {@link EventBus} . Events are produced by
  * {@link BGPMock}, and each instance notifies exactly one {@link BGPSessionListener}.
  */
-class EventBusRegistration extends ListenerRegistration<BGPSessionListener> {
+final class EventBusRegistration extends ListenerRegistration<BGPSessionListener> {
        private final EventBus eventBus;
 
        public static EventBusRegistration createAndRegister(final EventBus eventBus, final BGPSessionListener listener,
index 626185a8e4ee955bd2e0bb19b86f7e5e92ba5d52..e7bdaeb9907b27c83ff521347e59fe8fad553ca0 100644 (file)
@@ -28,19 +28,23 @@ import com.google.common.base.Preconditions;
 @ThreadSafe
 public abstract class AbstractAdjRIBsIn<ID, DATA extends DataObject> implements AdjRIBsIn {
        protected abstract class RIBEntryData {
-               final PathAttributes attributes;
+               private final PathAttributes attributes;
 
                protected RIBEntryData(final PathAttributes attributes) {
                        this.attributes = Preconditions.checkNotNull(attributes);
                }
 
+               public PathAttributes getPathAttributes() {
+                       return this.attributes;
+               }
+
                protected abstract DATA getDataObject(ID key);
        }
 
        /**
-        * A single RIB table entry, which holds multiple versions of the entry's state and elects the authoritative based on
-        * ordering specified by the supplied comparator.
-        *
+        * A single RIB table entry, which holds multiple versions of the entry's state and elects the authoritative based
+        * on ordering specified by the supplied comparator.
+        * 
         */
        private final class RIBEntry {
                /*
@@ -61,16 +65,16 @@ public abstract class AbstractAdjRIBsIn<ID, DATA extends DataObject> implements
                }
 
                private InstanceIdentifier<?> getName() {
-                       if (name == null) {
-                               name = identifierForKey(basePath, key);
+                       if (this.name == null) {
+                               this.name = identifierForKey(AbstractAdjRIBsIn.this.basePath, this.key);
                        }
-                       return name;
+                       return this.name;
                }
 
                private RIBEntryData findCandidate(final RIBEntryData initial) {
                        RIBEntryData newState = initial;
                        for (final RIBEntryData s : this.candidates.values()) {
-                               if (newState == null || comparator.compare(newState.attributes, s.attributes) > 0) {
+                               if (newState == null || AbstractAdjRIBsIn.this.comparator.compare(newState.attributes, s.attributes) > 0) {
                                        newState = s;
                                }
                        }
@@ -80,7 +84,7 @@ public abstract class AbstractAdjRIBsIn<ID, DATA extends DataObject> implements
 
                private void electCandidate(final DataModificationTransaction transaction, final RIBEntryData candidate) {
                        if (this.currentState == null || !this.currentState.equals(candidate)) {
-                               transaction.putRuntimeData(getName(), candidate.getDataObject(key));
+                               transaction.putRuntimeData(getName(), candidate.getDataObject(this.key));
                                this.currentState = candidate;
                        }
                }
@@ -93,12 +97,12 @@ public abstract class AbstractAdjRIBsIn<ID, DATA extends DataObject> implements
                                electCandidate(transaction, candidate);
                                return true;
                        } else {
-                               transaction.removeRuntimeData(name);
+                               transaction.removeRuntimeData(this.name);
                                return false;
                        }
                }
 
-               synchronized void setState(final DataModificationTransaction  transaction, final Peer peer, final RIBEntryData state) {
+               synchronized void setState(final DataModificationTransaction transaction, final Peer peer, final RIBEntryData state) {
                        this.candidates.put(peer, state);
                        electCandidate(transaction, findCandidate(state));
                }
@@ -111,7 +115,7 @@ public abstract class AbstractAdjRIBsIn<ID, DATA extends DataObject> implements
 
        protected AbstractAdjRIBsIn(final Comparator<PathAttributes> comparator, final TablesKey key) {
                this.comparator = Preconditions.checkNotNull(comparator);
-               basePath = InstanceIdentifier.builder().node(LocRib.class).node(Tables.class, key).toInstance();
+               this.basePath = InstanceIdentifier.builder().node(LocRib.class).node(Tables.class, key).toInstance();
        }
 
        @Override
@@ -128,7 +132,7 @@ public abstract class AbstractAdjRIBsIn<ID, DATA extends DataObject> implements
 
        protected abstract InstanceIdentifier<?> identifierForKey(final InstanceIdentifier<?> basePath, final ID id);
 
-       protected synchronized void add(final DataModificationTransaction  trans, final Peer peer, final ID id, final RIBEntryData data) {
+       protected synchronized void add(final DataModificationTransaction trans, final Peer peer, final ID id, final RIBEntryData data) {
                RIBEntry e = this.entries.get(id);
                if (e == null) {
                        e = new RIBEntry(id);
@@ -138,7 +142,7 @@ public abstract class AbstractAdjRIBsIn<ID, DATA extends DataObject> implements
                e.setState(trans, peer, data);
        }
 
-       protected synchronized void remove(final DataModificationTransaction  trans, final Peer peer, final ID id) {
+       protected synchronized void remove(final DataModificationTransaction trans, final Peer peer, final ID id) {
                final RIBEntry e = this.entries.get(id);
                if (e != null && e.removeState(trans, peer)) {
                        this.entries.remove(id);
index 95e7ff3a2d8673be7f93ed483362f6e4ae77e871..5d419a28de8bd2b32ea52765f17a21357e781964 100644 (file)
@@ -31,8 +31,9 @@ public class Main {
 
        private final static Logger logger = LoggerFactory.getLogger(Main.class);
 
-       public static String usage = "DESCRIPTION:\n" + "\tCreates a server with given parameters. As long as it runs, it accepts connections "
-                       + "from PCCs.\n" + "USAGE:\n" + "\t-a, --address\n" + "\t\tthe ip address to which is this server bound.\n"
+       private static String usage = "DESCRIPTION:\n"
+                       + "\tCreates a server with given parameters. As long as it runs, it accepts connections " + "from PCCs.\n" + "USAGE:\n"
+                       + "\t-a, --address\n" + "\t\tthe ip address to which is this server bound.\n"
                        + "\t\tFormat: x.x.x.x:y where y is port number.\n\n"
                        + "\t\tThis IP address will appear in BGP Open message as BGP Identifier of the server.\n" +
 
@@ -46,11 +47,10 @@ public class Main {
 
                        "With no parameters, this help is printed.";
 
-       BGPDispatcherImpl dispatcher;
+       private final BGPDispatcherImpl dispatcher;
 
        public Main() throws Exception {
-               this.dispatcher = new BGPDispatcherImpl(new BGPMessageFactoryImpl(
-                               ServiceLoaderBGPExtensionProviderContext.createConsumerContext().getMessageRegistry()));
+               this.dispatcher = new BGPDispatcherImpl(new BGPMessageFactoryImpl(ServiceLoaderBGPExtensionProviderContext.createConsumerContext().getMessageRegistry()));
        }
 
        public static void main(final String[] args) throws Exception {
@@ -76,7 +76,7 @@ public class Main {
                                as = new AsNumber(Long.valueOf(args[i + 1]));
                                i++;
                        } else {
-                               System.out.println("WARNING: Unrecognized argument: " + args[i]);
+                               logger.error("WARNING: Unrecognized argument: " + args[i]);
                        }
                        i++;
                }
index 9e31fcbed6a8ceb8fd4a65931c08cecd16e5e8ef..b44a5dae5310f0ea9881d541d773b7443c741144 100644 (file)
@@ -29,9 +29,13 @@ import com.google.common.primitives.UnsignedBytes;
 public final class BinaryBGPDumpFileParser {
 
        private static final byte ff = (byte) 255;
-       private static final Logger LOG = LoggerFactory.getLogger(BinaryBGPDumpFileParser.class);
+       private static final Logger logger = LoggerFactory.getLogger(BinaryBGPDumpFileParser.class);
        private static final int MINIMAL_LENGTH = 19;
 
+       private BinaryBGPDumpFileParser() {
+
+       }
+
        /**
         * Extract BGP messages from binary file in MRT format.
         * 
@@ -75,7 +79,7 @@ public final class BinaryBGPDumpFileParser {
                        }
 
                }
-               LOG.info("Succesfully extracted " + messages.size() + " messages");
+               logger.info("Succesfully extracted {} messages", messages.size());
                return messages;
        }
 }
index 0a2d44d2a956492187a4a125f38c9b14cc224972..02cd0f68db0ffe0e385a4d785d19f2a14c9f464f 100644 (file)
@@ -30,15 +30,20 @@ import com.google.common.collect.Lists;
 import com.google.common.io.CharStreams;
 
 /**
- * Read text file, parse BGP messages. File can contain comments or other data. BGP messages are detected using 16 ff marker.
- * New lines and spaces are ignored. Use {@link ByteArray#bytesToHexString(byte[])} for serializing bytes to this format.
+ * Read text file, parse BGP messages. File can contain comments or other data. BGP messages are detected using 16 ff
+ * marker. New lines and spaces are ignored. Use {@link ByteArray#bytesToHexString(byte[])} for serializing bytes to
+ * this format.
  */
 @Immutable
 public class HexDumpBGPFileParser {
        private static final int MINIMAL_LENGTH = 19;
-       private static final Logger LOG = LoggerFactory.getLogger(HexDumpBGPFileParser.class);
+       private static final Logger logger = LoggerFactory.getLogger(HexDumpBGPFileParser.class);
        private static final String ff_16 = Strings.repeat("FF", 16);
 
+       private HexDumpBGPFileParser() {
+
+       }
+
        public static List<byte[]> parseMessages(final File file) throws FileNotFoundException, IOException {
                Preconditions.checkArgument(file != null, "Filename cannot be null");
                return parseMessages(new FileInputStream(file));
@@ -54,47 +59,46 @@ public class HexDumpBGPFileParser {
        }
 
        public static List<byte[]> parseMessages(String content) {
-               content = clearWhiteSpace_toUpper(content);
+               content = clearWhiteSpaceToUpper(content);
                // search for 16 FFs
 
-               List<byte[]> messages = Lists.newLinkedList();
+               final List<byte[]> messages = Lists.newLinkedList();
                int idx = 0;
                while ((idx = content.indexOf(ff_16, idx)) > -1) {
                        // next 2 bytes are length
-                       int lengthIdx = idx + 16 * 2;
-                       int messageIdx = lengthIdx + 4;
-                       String hexLength = content.substring(lengthIdx, messageIdx);
+                       final int lengthIdx = idx + 16 * 2;
+                       final int messageIdx = lengthIdx + 4;
+                       final String hexLength = content.substring(lengthIdx, messageIdx);
                        byte[] byteLength = null;
                        try {
                                byteLength = Hex.decodeHex(hexLength.toCharArray());
-                       } catch (DecoderException e) {
+                       } catch (final DecoderException e) {
                                throw new RuntimeException(e);
                        }
-                       int length = ByteArray.bytesToInt(byteLength);
-                       int messageEndIdx = idx + length * 2;
+                       final int length = ByteArray.bytesToInt(byteLength);
+                       final int messageEndIdx = idx + length * 2;
 
                        // Assert that message is longer than minimum 19(header.length == 19)
                        // If length in BGP message would be 0, loop would never end
-                       Preconditions.checkArgument(length >=  MINIMAL_LENGTH,
-                                       "Invalid message at index " + idx
-                                       + ", length atribute is lower than " + MINIMAL_LENGTH);
+                       Preconditions.checkArgument(length >= MINIMAL_LENGTH, "Invalid message at index " + idx + ", length atribute is lower than "
+                                       + MINIMAL_LENGTH);
 
-                       String hexMessage = content.substring(idx, messageEndIdx);
+                       final String hexMessage = content.substring(idx, messageEndIdx);
                        byte[] message = null;
                        try {
                                message = Hex.decodeHex(hexMessage.toCharArray());
-                       } catch (DecoderException e) {
+                       } catch (final DecoderException e) {
                                new RuntimeException(e);
                        }
                        messages.add(message);
                        idx = messageEndIdx;
                }
-               LOG.info("Succesfully extracted " + messages.size() + " messages");
+               logger.info("Succesfully extracted {} messages", messages.size());
                return messages;
        }
 
        @VisibleForTesting
-       static String clearWhiteSpace_toUpper(final String line){
+       static String clearWhiteSpaceToUpper(final String line) {
                return line.replaceAll("\\s", "").toUpperCase();
        }
 
index f66e7595678ba2c81effcf27d52f6d10494ddca7..e1a9283b14e5d78f8bc92e0db62a8a7cda0c4754 100644 (file)
@@ -27,7 +27,7 @@ public class BGPHexFileParserTest {
        @Test
        public void testCleanWhiteSpace() {
                final String input = "abc def\r\nghi\nj";
-               assertEquals("ABCDEFGHIJ", HexDumpBGPFileParser.clearWhiteSpace_toUpper(input));
+               assertEquals("ABCDEFGHIJ", HexDumpBGPFileParser.clearWhiteSpaceToUpper(input));
        }
 
        @Test