Bug-731: Fixed few major Sonar warnings 85/9785/5
authorMilos Fabian <milfabia@cisco.com>
Thu, 7 Aug 2014 13:39:16 +0000 (15:39 +0200)
committerMilos Fabian <milfabia@cisco.com>
Tue, 12 Aug 2014 07:18:02 +0000 (09:18 +0200)
Change-Id: Ic176a1f7e5478721571b8efdab470bd0dad760d6
Signed-off-by: Milos Fabian <milfabia@cisco.com>
34 files changed:
bgp/linkstate/src/main/java/org/opendaylight/controller/config/yang/bgp/linkstate/LinkstateModule.java
bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/LinkstateAttributeParser.java
bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/BGPNotificationMessageParser.java
bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/BGPOpenMessageParser.java
bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/BGPUpdateMessageParser.java
bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/open/GracefulCapabilityHandler.java
bgp/parser-spi/src/main/java/org/opendaylight/protocol/bgp/parser/spi/pojo/SimpleBGPExtensionConsumerContext.java
bgp/parser-spi/src/main/java/org/opendaylight/protocol/bgp/parser/spi/pojo/SimpleBGPExtensionProviderContext.java
bgp/rib-impl/src/main/java/org/opendaylight/controller/config/yang/bgp/rib/impl/RIBImplModule.java
bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/BGPSessionImpl.java
bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/SpeakerSessionMock.java
bgp/rib-spi/src/main/java/org/opendaylight/protocol/bgp/rib/spi/BGPObjectComparator.java
bgp/testtool/src/main/java/org/opendaylight/protocol/bgp/testtool/Main.java
bgp/topology-provider/src/main/java/org/opendaylight/bgpcep/bgp/topology/provider/LinkstateTopologyBuilder.java
bgp/topology-provider/src/main/java/org/opendaylight/bgpcep/bgp/topology/provider/UriBuilder.java
pcep/ietf-stateful02/src/main/java/org/opendaylight/protocol/pcep/ietf/stateful02/Stateful02PCRequestMessageParser.java
pcep/ietf-stateful07/src/main/java/org/opendaylight/controller/config/yang/pcep/stateful07/cfg/Stateful07PCEPSessionProposalFactoryModule.java
pcep/ietf-stateful07/src/main/java/org/opendaylight/protocol/pcep/ietf/initiated00/CInitiated00LspObjectParser.java
pcep/ietf-stateful07/src/main/java/org/opendaylight/protocol/pcep/ietf/stateful07/Stateful07LspObjectParser.java
pcep/impl/src/main/java/org/opendaylight/controller/config/yang/pcep/impl/PCEPDispatcherImplModule.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/PCEPSessionImpl.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/message/PCEPRequestMessageParser.java
pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/FiniteStateMachineTest.java
pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/VendorInformationUtil.java
pcep/testtool/src/main/java/org/opendaylight/protocol/pcep/testtool/Main.java
pcep/testtool/src/main/java/org/opendaylight/protocol/pcep/testtool/SimpleSessionListener.java
pcep/testtool/src/main/java/org/opendaylight/protocol/pcep/testtool/TestingSessionListener.java
pcep/testtool/src/test/java/org/opendaylight/protocol/pcep/testtool/PCEPTestingToolTest.java
pcep/topology-provider/src/main/java/org/opendaylight/bgpcep/pcep/topology/provider/AbstractTopologySessionListener.java
pcep/topology-provider/src/main/java/org/opendaylight/bgpcep/pcep/topology/provider/Stateful02TopologySessionListener.java
pcep/topology-provider/src/main/java/org/opendaylight/bgpcep/pcep/topology/provider/Stateful07TopologySessionListener.java
pcep/topology-provider/src/main/java/org/opendaylight/controller/config/yang/pcep/topology/provider/PCEPTopologyProviderModule.java
programming/impl/src/main/java/org/opendaylight/controller/config/yang/programming/impl/InstructionSchedulerImplModule.java
util/src/main/java/org/opendaylight/protocol/util/ByteArray.java

index 5715e112fcd03d6a9fa729f654aff5d83cd56c2d..06a6220af4bb4c47288c0b3ae0b2894a2f334929 100644 (file)
@@ -47,8 +47,8 @@ public final class LinkstateModule extends org.opendaylight.controller.config.ya
     @Override
     public java.lang.AutoCloseable createInstance() {
         final class LinkstateExtension implements AutoCloseable, BGPExtensionProviderActivator, RIBExtensionProviderActivator {
-            final BGPExtensionProviderActivator bgpact = new BGPActivator(getIanaLinkstateAttributeType());
-            final RIBExtensionProviderActivator ribact = new RIBActivator();
+            private final BGPExtensionProviderActivator bgpact = new BGPActivator(getIanaLinkstateAttributeType());
+            private final RIBExtensionProviderActivator ribact = new RIBActivator();
 
             @Override
             public void close() {
index a997520e4dbb102fd41908b71179f9b63fc39c18..a623f234ea9caf18f4ebab6bea99f7f80403084d 100644 (file)
@@ -151,12 +151,12 @@ public class LinkstateAttributeParser implements AttributeParser, AttributeSeria
 
     @Override
     public void parseAttribute(final ByteBuf buffer, final PathAttributesBuilder builder) throws BGPParsingException {
-        final NlriType type = getNlriType(builder);
-        if (type == null) {
+        final NlriType nlriType = getNlriType(builder);
+        if (nlriType == null) {
             LOG.warn("No Linkstate NLRI found, not parsing Linkstate attribute");
             return;
         }
-        final PathAttributes1 a = new PathAttributes1Builder().setLinkstatePathAttribute(parseLinkState(type, buffer)).build();
+        final PathAttributes1 a = new PathAttributes1Builder().setLinkstatePathAttribute(parseLinkState(nlriType, buffer)).build();
         builder.addAugmentation(PathAttributes1.class, a);
     }
 
index 2868c09cab3fe536faf95b293d81be30d0140502..87bc1c3bffea528a1386e445428103959f499c41 100644 (file)
@@ -43,7 +43,7 @@ public final class BGPNotificationMessageParser implements MessageParser, Messag
      */
     @Override
     public void serializeMessage(final Notification msg, final ByteBuf bytes) {
-        Preconditions.checkArgument(msg != null && msg instanceof Notify, "BGP Notification message cannot be null");
+        Preconditions.checkArgument(msg instanceof Notify, "BGP Notification message cannot be null");
         final Notify ntf = (Notify) msg;
         LOG.trace("Started serializing Notification message: {}", ntf);
 
index 4c47d9c699d6ac07d2e6e485b1cf7826412993e6..1694c73d70b63244eb1832ad1142f1df8bb64a06 100644 (file)
@@ -66,7 +66,7 @@ public final class BGPOpenMessageParser implements MessageParser, MessageSeriali
      */
     @Override
     public void serializeMessage(final Notification msg, final ByteBuf bytes) {
-        Preconditions.checkArgument(msg != null && msg instanceof Open, "BGP Open message cannot be null");
+        Preconditions.checkArgument(msg instanceof Open, "BGP Open message cannot be null");
         LOG.trace("Started serializing open message: {}", msg);
         final Open open = (Open) msg;
         final ByteBuf msgBody = Unpooled.buffer();
index b0c266fe73920c80ffd7edf32d8cccd0d2303d65..2fbc681c233e5823a0a1ffd849532c4bcf1b9a13 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
+ * 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,
@@ -101,7 +101,7 @@ public class BGPUpdateMessageParser implements MessageParser, MessageSerializer
 
     @Override
     public void serializeMessage(final Notification message, final ByteBuf bytes) {
-        Preconditions.checkArgument(message != null && message instanceof Update, "BGPUpdate message cannot be null");
+        Preconditions.checkArgument(message instanceof Update, "BGPUpdate message cannot be null");
         LOG.trace("Started serializing update message: {}", message);
         final Update update = (Update) message;
 
index cda8c5fac3f780798e76761a4d319d61f3d3948e..1c4ab7224825008e4c8aab8303abddfb30f0896d 100644 (file)
@@ -55,6 +55,8 @@ public final class GracefulCapabilityHandler implements CapabilityParser, Capabi
 
     private static final int AFI_FLAG_FORWARDING_STATE = 0x80;
 
+    private static final int MAX_RESTART_TIME = 4095;
+
     private final AddressFamilyRegistry afiReg;
     private final SubsequentAddressFamilyRegistry safiReg;
 
@@ -79,7 +81,7 @@ public final class GracefulCapabilityHandler implements CapabilityParser, Capabi
         int timeval = 0;
         final Integer time = grace.getRestartTime();
         if (time != null) {
-            Preconditions.checkArgument(time >= 0 && time <= 4095);
+            Preconditions.checkArgument(time >= 0 && time <= MAX_RESTART_TIME);
             timeval = time;
         }
         bytes.writeByte(flagBits + timeval / 256);
index ea6c7681571d837e6eaf84a38e8f0006c81d8fc9..e134af00072167713c5dce26127fcd9395825252 100644 (file)
@@ -7,56 +7,49 @@
  */
 package org.opendaylight.protocol.bgp.parser.spi.pojo;
 
-import org.opendaylight.protocol.bgp.parser.spi.AddressFamilyRegistry;
-import org.opendaylight.protocol.bgp.parser.spi.AttributeRegistry;
 import org.opendaylight.protocol.bgp.parser.spi.BGPExtensionConsumerContext;
-import org.opendaylight.protocol.bgp.parser.spi.CapabilityRegistry;
-import org.opendaylight.protocol.bgp.parser.spi.MessageRegistry;
-import org.opendaylight.protocol.bgp.parser.spi.NlriRegistry;
-import org.opendaylight.protocol.bgp.parser.spi.ParameterRegistry;
-import org.opendaylight.protocol.bgp.parser.spi.SubsequentAddressFamilyRegistry;
 
 class SimpleBGPExtensionConsumerContext implements BGPExtensionConsumerContext {
-    protected final SimpleAddressFamilyRegistry afiReg = new SimpleAddressFamilyRegistry();
-    protected final SimpleAttributeRegistry attrReg = new SimpleAttributeRegistry();
-    protected final SimpleCapabilityRegistry capReg = new SimpleCapabilityRegistry();
-    protected final SimpleMessageRegistry msgReg = new SimpleMessageRegistry();
-    protected final SimpleSubsequentAddressFamilyRegistry safiReg = new SimpleSubsequentAddressFamilyRegistry();
-    protected final SimpleParameterRegistry paramReg = new SimpleParameterRegistry();
-    protected final SimpleNlriRegistry nlriReg = new SimpleNlriRegistry(this.afiReg, this.safiReg);
+    private final SimpleAddressFamilyRegistry afiReg = new SimpleAddressFamilyRegistry();
+    private final SimpleAttributeRegistry attrReg = new SimpleAttributeRegistry();
+    private final SimpleCapabilityRegistry capReg = new SimpleCapabilityRegistry();
+    private final SimpleMessageRegistry msgReg = new SimpleMessageRegistry();
+    private final SimpleSubsequentAddressFamilyRegistry safiReg = new SimpleSubsequentAddressFamilyRegistry();
+    private final SimpleParameterRegistry paramReg = new SimpleParameterRegistry();
+    private final SimpleNlriRegistry nlriReg = new SimpleNlriRegistry(this.afiReg, this.safiReg);
 
     @Override
-    public final AddressFamilyRegistry getAddressFamilyRegistry() {
+    public final SimpleAddressFamilyRegistry getAddressFamilyRegistry() {
         return this.afiReg;
     }
 
     @Override
-    public final AttributeRegistry getAttributeRegistry() {
+    public final SimpleAttributeRegistry getAttributeRegistry() {
         return this.attrReg;
     }
 
     @Override
-    public final CapabilityRegistry getCapabilityRegistry() {
+    public final SimpleCapabilityRegistry getCapabilityRegistry() {
         return this.capReg;
     }
 
     @Override
-    public final MessageRegistry getMessageRegistry() {
+    public final SimpleMessageRegistry getMessageRegistry() {
         return this.msgReg;
     }
 
     @Override
-    public final NlriRegistry getNlriRegistry() {
+    public final SimpleNlriRegistry getNlriRegistry() {
         return this.nlriReg;
     }
 
     @Override
-    public final ParameterRegistry getParameterRegistry() {
+    public final SimpleParameterRegistry getParameterRegistry() {
         return this.paramReg;
     }
 
     @Override
-    public final SubsequentAddressFamilyRegistry getSubsequentAddressFamilyRegistry() {
+    public final SimpleSubsequentAddressFamilyRegistry getSubsequentAddressFamilyRegistry() {
         return this.safiReg;
     }
 }
index 460fab3a9971a92ba5fd35517b76e5f7a46f4e42..9401acd3e8cd3547fe0673c7d4b286e59fb37334 100644 (file)
@@ -10,9 +10,7 @@ package org.opendaylight.protocol.bgp.parser.spi.pojo;
 import com.google.common.base.Preconditions;
 import com.google.common.cache.Cache;
 import com.google.common.cache.CacheBuilder;
-
 import java.util.concurrent.atomic.AtomicReference;
-
 import org.opendaylight.protocol.bgp.parser.spi.AttributeParser;
 import org.opendaylight.protocol.bgp.parser.spi.AttributeSerializer;
 import org.opendaylight.protocol.bgp.parser.spi.BGPExtensionProviderContext;
@@ -67,63 +65,63 @@ public class SimpleBGPExtensionProviderContext extends SimpleBGPExtensionConsume
 
     @Override
     public AutoCloseable registerAddressFamily(final Class<? extends AddressFamily> clazz, final int number) {
-        return this.afiReg.registerAddressFamily(clazz, number);
+        return this.getAddressFamilyRegistry().registerAddressFamily(clazz, number);
     }
 
     @Override
     public AutoCloseable registerAttributeParser(final int attributeType, final AttributeParser parser) {
-        return this.attrReg.registerAttributeParser(attributeType, parser);
+        return this.getAttributeRegistry().registerAttributeParser(attributeType, parser);
     }
 
     @Override
     public AutoCloseable registerAttributeSerializer(final Class<? extends DataObject> attributeClass, final AttributeSerializer serializer) {
-        return this.attrReg.registerAttributeSerializer(attributeClass, serializer);
+        return this.getAttributeRegistry().registerAttributeSerializer(attributeClass, serializer);
     }
 
     @Override
     public AutoCloseable registerCapabilityParser(final int capabilityType, final CapabilityParser parser) {
-        return this.capReg.registerCapabilityParser(capabilityType, parser);
+        return this.getCapabilityRegistry().registerCapabilityParser(capabilityType, parser);
     }
 
     @Override
     public AutoCloseable registerCapabilitySerializer(final Class<? extends CParameters> capabilityClass, final CapabilitySerializer serializer) {
-        return this.capReg.registerCapabilitySerializer(capabilityClass, serializer);
+        return this.getCapabilityRegistry().registerCapabilitySerializer(capabilityClass, serializer);
     }
 
     @Override
     public AutoCloseable registerMessageParser(final int messageType, final MessageParser parser) {
-        return this.msgReg.registerMessageParser(messageType, parser);
+        return this.getMessageRegistry().registerMessageParser(messageType, parser);
     }
 
     @Override
     public AutoCloseable registerMessageSerializer(final Class<? extends Notification> messageClass, final MessageSerializer serializer) {
-        return this.msgReg.registerMessageSerializer(messageClass, serializer);
+        return this.getMessageRegistry().registerMessageSerializer(messageClass, serializer);
     }
 
     @Override
     public AutoCloseable registerNlriParser(final Class<? extends AddressFamily> afi, final Class<? extends SubsequentAddressFamily> safi,
             final NlriParser parser) {
-        return this.nlriReg.registerNlriParser(afi, safi, parser);
+        return this.getNlriRegistry().registerNlriParser(afi, safi, parser);
     }
 
     @Override
     public AutoCloseable registerNlriSerializer(final Class<? extends DataObject> nlriClass, final NlriSerializer serializer) {
-        return this.nlriReg.registerNlriSerializer(nlriClass,serializer);
+        return this.getNlriRegistry().registerNlriSerializer(nlriClass,serializer);
     }
 
     @Override
     public AutoCloseable registerParameterParser(final int parameterType, final ParameterParser parser) {
-        return this.paramReg.registerParameterParser(parameterType, parser);
+        return this.getParameterRegistry().registerParameterParser(parameterType, parser);
     }
 
     @Override
     public AutoCloseable registerParameterSerializer(final Class<? extends BgpParameters> paramClass, final ParameterSerializer serializer) {
-        return this.paramReg.registerParameterSerializer(paramClass, serializer);
+        return this.getParameterRegistry().registerParameterSerializer(paramClass, serializer);
     }
 
     @Override
     public AutoCloseable registerSubsequentAddressFamily(final Class<? extends SubsequentAddressFamily> clazz, final int number) {
-        return this.safiReg.registerSubsequentAddressFamily(clazz, number);
+        return this.getSubsequentAddressFamilyRegistry().registerSubsequentAddressFamily(clazz, number);
     }
 
     @Override
index 38efbb20e6364d8c4c859d2679942b42aad7b968..6d2bbe4ae938bbfe86da52241c6bc0ccfe89bbc5 100644 (file)
@@ -25,6 +25,8 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.
  */
 public final class RIBImplModule extends org.opendaylight.controller.config.yang.bgp.rib.impl.AbstractRIBImplModule {
 
+    private static final String IS_NOT_SET = "is not set.";
+
     public RIBImplModule(final org.opendaylight.controller.config.api.ModuleIdentifier name,
             final org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
         super(name, dependencyResolver);
@@ -38,13 +40,13 @@ public final class RIBImplModule extends org.opendaylight.controller.config.yang
 
     @Override
     public void customValidation() {
-        JmxAttributeValidationException.checkNotNull(getExtensions(), "is not set.", extensionsJmxAttribute);
-        JmxAttributeValidationException.checkNotNull(getRibId(), "is not set.", ribIdJmxAttribute);
-        JmxAttributeValidationException.checkNotNull(getLocalAs(), "is not set.", localAsJmxAttribute);
-        JmxAttributeValidationException.checkNotNull(getBgpId(), "is not set.", bgpIdJmxAttribute);
-        JmxAttributeValidationException.checkNotNull(getTcpReconnectStrategy(), "is not set.", tcpReconnectStrategyJmxAttribute);
-        JmxAttributeValidationException.checkNotNull(getSessionReconnectStrategy(), "is not set.", sessionReconnectStrategyJmxAttribute);
-        JmxAttributeValidationException.checkNotNull(getLocalTable(), "is not set.", localTableJmxAttribute);
+        JmxAttributeValidationException.checkNotNull(getExtensions(), IS_NOT_SET, extensionsJmxAttribute);
+        JmxAttributeValidationException.checkNotNull(getRibId(), IS_NOT_SET, ribIdJmxAttribute);
+        JmxAttributeValidationException.checkNotNull(getLocalAs(), IS_NOT_SET, localAsJmxAttribute);
+        JmxAttributeValidationException.checkNotNull(getBgpId(), IS_NOT_SET, bgpIdJmxAttribute);
+        JmxAttributeValidationException.checkNotNull(getTcpReconnectStrategy(), IS_NOT_SET, tcpReconnectStrategyJmxAttribute);
+        JmxAttributeValidationException.checkNotNull(getSessionReconnectStrategy(), IS_NOT_SET, sessionReconnectStrategyJmxAttribute);
+        JmxAttributeValidationException.checkNotNull(getLocalTable(), IS_NOT_SET, localTableJmxAttribute);
     }
 
     @Override
index 4c1cf57c67da2e01e86ef66bc033539774fe2e5c..bcd9b18e9a24b9d3d5a775527a02c5ce764833c3 100644 (file)
@@ -12,16 +12,12 @@ import com.google.common.base.Objects;
 import com.google.common.base.Objects.ToStringHelper;
 import com.google.common.base.Preconditions;
 import com.google.common.collect.Sets;
-
 import io.netty.channel.Channel;
-
 import java.io.IOException;
 import java.util.Date;
 import java.util.Set;
 import java.util.concurrent.TimeUnit;
-
 import javax.annotation.concurrent.GuardedBy;
-
 import org.opendaylight.protocol.bgp.parser.AsNumberUtil;
 import org.opendaylight.protocol.bgp.parser.BGPError;
 import org.opendaylight.protocol.bgp.parser.BgpTableTypeImpl;
@@ -74,10 +70,10 @@ public class BGPSessionImpl extends AbstractProtocolSession<Notification> implem
     }
 
     /**
-     * System.nanoTime value about when was sent the last message Protected to be updated also in tests.
+     * System.nanoTime value about when was sent the last message.
      */
     @VisibleForTesting
-    protected long lastMessageSentAt;
+    private long lastMessageSentAt;
 
     /**
      * System.nanoTime value about when was received the last message
@@ -322,4 +318,9 @@ public class BGPSessionImpl extends AbstractProtocolSession<Notification> implem
         channel.eventLoop().submit(task);
 
     }
+
+    @VisibleForTesting
+    protected void setLastMessageSentAt(final long lastMessageSentAt) {
+        this.lastMessageSentAt = lastMessageSentAt;
+    }
 }
index c3cadacdcbf6d069e91fc6014bbe6394486ae795..72bdf15dcec517accff6f78a2bd0307b639fa7dc 100644 (file)
@@ -8,8 +8,8 @@
 package org.opendaylight.protocol.bgp.rib.impl;
 
 import static org.mockito.Mockito.mock;
-import io.netty.channel.Channel;
 
+import io.netty.channel.Channel;
 import org.opendaylight.protocol.bgp.rib.spi.BGPSessionListener;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.OpenBuilder;
 import org.opendaylight.yangtools.yang.binding.Notification;
@@ -28,7 +28,7 @@ public class SpeakerSessionMock extends BGPSessionImpl {
 
     @Override
     public void sendMessage(final Notification msg) {
-        this.lastMessageSentAt = System.nanoTime();
+        this.setLastMessageSentAt(System.nanoTime());
         this.client.onMessage(this, msg);
     }
 }
index b4409ed9d974e31190ecf5688d80ed29a413b762..08c1e820309486494e7622633bf88e07e71c614a 100644 (file)
@@ -10,11 +10,9 @@ package org.opendaylight.protocol.bgp.rib.spi;
 import com.google.common.annotations.VisibleForTesting;
 import com.google.common.base.Preconditions;
 import com.google.common.net.InetAddresses;
-
 import java.util.Arrays;
 import java.util.Comparator;
 import java.util.List;
-
 import org.opendaylight.protocol.bgp.rib.spi.AbstractAdjRIBs.RIBEntryData;
 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.rev130919.PathAttributes;
@@ -115,7 +113,6 @@ public final class BGPObjectComparator implements Comparator<RIBEntryData<?, ?,
         // 9. When both paths are external, prefer the path that was received first (the oldest one).
         // if (first.equals(this.ourAS) && second.equals(this.ourAS)) {
         // FIXME: do we have a way how to determine which one was received first?
-        // }
 
         // 10. Prefer the route that comes from the BGP router with the lowest router ID.
         // The router ID is the highest IP address on the router, with preference given to loopback addresses.
index 6104152469d60893dc22c2779b4a546f90d3ee24..026df45b4bec3a834a3dd7a75fa33a4edc9bb48d 100644 (file)
@@ -11,6 +11,7 @@ import io.netty.channel.nio.NioEventLoopGroup;
 import io.netty.util.concurrent.GlobalEventExecutor;
 import java.net.InetAddress;
 import java.net.InetSocketAddress;
+import java.net.UnknownHostException;
 import java.util.HashMap;
 import java.util.Map;
 import org.opendaylight.protocol.bgp.parser.impl.BGPActivator;
@@ -61,13 +62,14 @@ public final class Main {
 
     private static final int RECONNECT_MILLIS = 5000;
 
-    private Main() throws Exception {
-        final BGPActivator bgpActivator = new BGPActivator();
-        bgpActivator.start(ServiceLoaderBGPExtensionProviderContext.getSingletonInstance());
-        this.dispatcher = new BGPDispatcherImpl(ServiceLoaderBGPExtensionProviderContext.getSingletonInstance().getMessageRegistry(), new NioEventLoopGroup(), new NioEventLoopGroup());
+    private Main() {
+        try (final BGPActivator bgpActivator = new BGPActivator()) {
+            bgpActivator.start(ServiceLoaderBGPExtensionProviderContext.getSingletonInstance());
+            this.dispatcher = new BGPDispatcherImpl(ServiceLoaderBGPExtensionProviderContext.getSingletonInstance().getMessageRegistry(), new NioEventLoopGroup(), new NioEventLoopGroup());
+        }
     }
 
-    public static void main(final String[] args) throws Exception {
+    public static void main(final String[] args) throws NumberFormatException, UnknownHostException {
         if (args.length == 0 || (args.length == 1 && args[0].equalsIgnoreCase("--help"))) {
             LOG.info(Main.USAGE);
             return;
index c0314e76da3c302752c006a147d79cc1ffcc2895..8f070ad319328459843dcea2fc8e40f1b7f68a2a 100644 (file)
@@ -346,7 +346,7 @@ public final class LinkstateTopologyBuilder extends AbstractTopologyBuilder<Link
         return buildTp(id, t);
     }
 
-    private InstanceIdentifier<Link> buildLinkIdentifier(final UriBuilder base, final LinkId id) {
+    private InstanceIdentifier<Link> buildLinkIdentifier(final LinkId id) {
         return getInstanceIdentifier().child(
                 org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Link.class,
                 new LinkKey(id));
@@ -512,7 +512,7 @@ public final class LinkstateTopologyBuilder extends AbstractTopologyBuilder<Link
         LOG.debug("Created TP {} as link destination", dstTp);
         putNode(trans, dnh);
 
-        final InstanceIdentifier<Link> lid = buildLinkIdentifier(base, lb.getLinkId());
+        final InstanceIdentifier<Link> lid = buildLinkIdentifier(lb.getLinkId());
         final Link link = lb.build();
 
         trans.put(LogicalDatastoreType.OPERATIONAL, lid, link);
@@ -532,7 +532,7 @@ public final class LinkstateTopologyBuilder extends AbstractTopologyBuilder<Link
 
     private void removeLink(final WriteTransaction trans, final UriBuilder base, final LinkCase l) {
         final LinkId id = buildLinkId(base, l);
-        final InstanceIdentifier<?> lid = buildLinkIdentifier(base, id);
+        final InstanceIdentifier<?> lid = buildLinkIdentifier(id);
         trans.delete(LogicalDatastoreType.OPERATIONAL, lid);
         LOG.debug("Removed link {}", lid);
 
index faa2c8e3de96280faaf9296fd28ebf7b3af10db4..82a5609d0f6461f1da360e74cb1799b6f1ce4dea 100644 (file)
@@ -76,13 +76,13 @@ final class UriBuilder {
     }
 
     private String isoId(final byte[] bytes) {
-        final StringBuilder sb = new StringBuilder();
-        sb.append(Hex.encodeHexString(new byte[] { bytes[0], bytes[1] }));
-        sb.append('.');
-        sb.append(Hex.encodeHexString(new byte[] { bytes[2], bytes[3] }));
-        sb.append('.');
-        sb.append(Hex.encodeHexString(new byte[] { bytes[4], bytes[5] }));
-        return sb.toString();
+        final StringBuilder sBuilder = new StringBuilder();
+        sBuilder.append(Hex.encodeHexString(new byte[] { bytes[0], bytes[1] }));
+        sBuilder.append('.');
+        sBuilder.append(Hex.encodeHexString(new byte[] { bytes[2], bytes[3] }));
+        sBuilder.append('.');
+        sBuilder.append(Hex.encodeHexString(new byte[] { bytes[4], bytes[5] }));
+        return sBuilder.toString();
     }
 
     private String formatRouterIdentifier(final CRouterIdentifier routerIdentifier) {
index 17199b34a9664f877605ee65e1687f4525e51d76..eaf0bb3b7e640cb0708bcbe192736de0d3f3a9ef 100644 (file)
@@ -200,7 +200,7 @@ public final class Stateful02PCRequestMessageParser extends PCEPRequestMessagePa
 
         if (rp.isReoptimization()
                 && builder.getBandwidth() != null
-                && builder.getReportedRoute().getBandwidth().getBandwidth() != new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.Bandwidth(new byte[] { 0 })
+                && !builder.getReportedRoute().getBandwidth().getBandwidth().equals(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.Bandwidth(new byte[] { 0 }))
                 && builder.getReportedRoute().getRro() == null) {
             errors.add(createErrorMsg(PCEPErrors.RRO_MISSING, Optional.of(rp)));
             return null;
index 044a92302642e6be42586822ca61f140ccd07c13..1b94444a13a7a6c585852593053bf5b9306492be 100644 (file)
@@ -8,9 +8,7 @@
 package org.opendaylight.controller.config.yang.pcep.stateful07.cfg;
 
 import com.google.common.base.Preconditions;
-
 import java.net.InetSocketAddress;
-
 import org.opendaylight.controller.config.api.JmxAttributeValidationException;
 import org.opendaylight.protocol.pcep.PCEPSessionProposalFactory;
 import org.opendaylight.protocol.pcep.ietf.initiated00.Stateful07SessionProposalFactory;
@@ -25,6 +23,10 @@ public final class Stateful07PCEPSessionProposalFactoryModule extends
         org.opendaylight.controller.config.yang.pcep.stateful07.cfg.AbstractStateful07PCEPSessionProposalFactoryModule {
     private static final Logger LOG = LoggerFactory.getLogger(Stateful07PCEPSessionProposalFactoryModule.class);
 
+    private static final String VALUE_IS_NOT_SET = "value is not set.";
+
+    private static final int DT_KA_RATIO = 4;
+
     public Stateful07PCEPSessionProposalFactoryModule(final org.opendaylight.controller.config.api.ModuleIdentifier identifier,
             final org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
         super(identifier, dependencyResolver);
@@ -39,14 +41,14 @@ public final class Stateful07PCEPSessionProposalFactoryModule extends
 
     @Override
     protected void customValidation() {
-        JmxAttributeValidationException.checkNotNull(getActive(), "value is not set.", activeJmxAttribute);
-        JmxAttributeValidationException.checkNotNull(getInitiated(), "value is not set.", initiatedJmxAttribute);
-        JmxAttributeValidationException.checkNotNull(getDeadTimerValue(), "value is not set.", deadTimerValueJmxAttribute);
-        JmxAttributeValidationException.checkNotNull(getKeepAliveTimerValue(), "value is not set.", keepAliveTimerValueJmxAttribute);
+        JmxAttributeValidationException.checkNotNull(getActive(), VALUE_IS_NOT_SET, activeJmxAttribute);
+        JmxAttributeValidationException.checkNotNull(getInitiated(), VALUE_IS_NOT_SET, initiatedJmxAttribute);
+        JmxAttributeValidationException.checkNotNull(getDeadTimerValue(), VALUE_IS_NOT_SET, deadTimerValueJmxAttribute);
+        JmxAttributeValidationException.checkNotNull(getKeepAliveTimerValue(), VALUE_IS_NOT_SET, keepAliveTimerValueJmxAttribute);
         if (getKeepAliveTimerValue() != 0) {
             JmxAttributeValidationException.checkCondition(getKeepAliveTimerValue() >= 1, "minimum value is 1.",
                     keepAliveTimerValueJmxAttribute);
-            if (getDeadTimerValue() != 0 && (getDeadTimerValue() / getKeepAliveTimerValue() != 4)) {
+            if (getDeadTimerValue() != 0 && (getDeadTimerValue() / getKeepAliveTimerValue() != DT_KA_RATIO)) {
                 LOG.warn("DeadTimerValue should be 4 times greater than KeepAliveTimerValue");
             }
         }
index 7a9975056c358ee1ebdecc97f00548a5f5dc655b..4446d4a50b368dae1fffa956b0a8b4f28a456b8e 100644 (file)
@@ -45,7 +45,7 @@ public class CInitiated00LspObjectParser extends Stateful07LspObjectParser {
         builder.setIgnore(header.isIgnore());
         builder.setProcessingRule(header.isProcessingRule());
         int[] plspIdRaw = new int[] { bytes.readUnsignedByte(), bytes.readUnsignedByte(), bytes.getUnsignedByte(2), };
-        builder.setPlspId(new PlspId((long) ((plspIdRaw[0] << 12) | (plspIdRaw[1] << 4) | (plspIdRaw[2] >> 4))));
+        builder.setPlspId(new PlspId((long) ((plspIdRaw[0] << TWELVE_BITS_SHIFT) | (plspIdRaw[1] << FOUR_BITS_SHIFT) | (plspIdRaw[2] >> FOUR_BITS_SHIFT))));
         final BitSet flags = ByteArray.bytesToBitSet(ByteArray.readBytes(bytes, 2));
         builder.setDelegate(flags.get(DELEGATE_FLAG_OFFSET));
         builder.setSync(flags.get(SYNC_FLAG_OFFSET));
@@ -69,31 +69,31 @@ public class CInitiated00LspObjectParser extends Stateful07LspObjectParser {
         final Lsp specObj = (Lsp) object;
         final ByteBuf body = Unpooled.buffer();
 
-        final byte[] retBytes = new byte[4];
+        final byte[] retBytes = new byte[BODY_LENGTH];
 
         Preconditions.checkArgument(specObj.getPlspId() != null, "PLSP-ID not present");
         final int lspID = specObj.getPlspId().getValue().intValue();
-        retBytes[0] = (byte) (lspID >> 12);
-        retBytes[1] = (byte) (lspID >> 4);
-        retBytes[2] = (byte) (lspID << 4);
+        retBytes[0] = (byte) (lspID >> TWELVE_BITS_SHIFT);
+        retBytes[1] = (byte) (lspID >> FOUR_BITS_SHIFT);
+        retBytes[2] = (byte) (lspID << FOUR_BITS_SHIFT);
         if (specObj.isDelegate() != null && specObj.isDelegate()) {
-            retBytes[3] |= 1 << (Byte.SIZE - (DELEGATE_FLAG_OFFSET - Byte.SIZE) - 1);
+            retBytes[FLAGS_INDEX] |= 1 << (Byte.SIZE - (DELEGATE_FLAG_OFFSET - Byte.SIZE) - 1);
         }
         if (specObj.isRemove() != null && specObj.isRemove()) {
-            retBytes[3] |= 1 << (Byte.SIZE - (REMOVE_FLAG_OFFSET - Byte.SIZE) - 1);
+            retBytes[FLAGS_INDEX] |= 1 << (Byte.SIZE - (REMOVE_FLAG_OFFSET - Byte.SIZE) - 1);
         }
         if (specObj.isSync() != null && specObj.isSync()) {
-            retBytes[3] |= 1 << (Byte.SIZE - (SYNC_FLAG_OFFSET - Byte.SIZE) - 1);
+            retBytes[FLAGS_INDEX] |= 1 << (Byte.SIZE - (SYNC_FLAG_OFFSET - Byte.SIZE) - 1);
         }
         if (specObj.isAdministrative() != null && specObj.isAdministrative()) {
-            retBytes[3] |= 1 << (Byte.SIZE - (ADMINISTRATIVE_FLAG_OFFSET - Byte.SIZE) - 1);
+            retBytes[FLAGS_INDEX] |= 1 << (Byte.SIZE - (ADMINISTRATIVE_FLAG_OFFSET - Byte.SIZE) - 1);
         }
         if (specObj.getAugmentation(Lsp1.class) != null && specObj.getAugmentation(Lsp1.class).isCreate()) {
-            retBytes[3] |= 1 << (Byte.SIZE - (CREATE_FLAG_OFFSET - Byte.SIZE) - 1);
+            retBytes[FLAGS_INDEX] |= 1 << (Byte.SIZE - (CREATE_FLAG_OFFSET - Byte.SIZE) - 1);
         }
         if (specObj.getOperational() != null) {
             final int op = specObj.getOperational().getIntValue();
-            retBytes[3] |= (op & 7) << 4;
+            retBytes[FLAGS_INDEX] |= (op & OP_VALUE_BITS_OFFSET) << FOUR_BITS_SHIFT;
         }
         body.writeBytes(retBytes);
         serializeTlvs(specObj.getTlvs(), body);
index 3db875c93c396131ad1bc15717fe39af31eea673..122ac09c896d4344aecbe34947cee5eb8e4b73c5 100644 (file)
@@ -58,6 +58,12 @@ public class Stateful07LspObjectParser extends AbstractObjectWithTlvsParser<Tlvs
     protected static final int ADMINISTRATIVE_FLAG_OFFSET = 12;
     protected static final int OPERATIONAL_OFFSET = 9;
 
+    protected static final int FOUR_BITS_SHIFT = 4;
+    protected static final int TWELVE_BITS_SHIFT = 12;
+    protected static final int BODY_LENGTH = 4;
+    protected static final int FLAGS_INDEX = 3;
+    protected static final int OP_VALUE_BITS_OFFSET = 7;
+
     public Stateful07LspObjectParser(final TlvRegistry tlvReg, final VendorInformationTlvRegistry viTlvReg) {
         super(tlvReg, viTlvReg);
     }
@@ -69,7 +75,7 @@ public class Stateful07LspObjectParser extends AbstractObjectWithTlvsParser<Tlvs
         builder.setIgnore(header.isIgnore());
         builder.setProcessingRule(header.isProcessingRule());
         int[] plspIdRaw = new int[] { bytes.readUnsignedByte(), bytes.readUnsignedByte(), bytes.getUnsignedByte(2), };
-        builder.setPlspId(new PlspId((long) ((plspIdRaw[0] << 12) | (plspIdRaw[1] << 4) | (plspIdRaw[2] >> 4))));
+        builder.setPlspId(new PlspId((long) ((plspIdRaw[0] << TWELVE_BITS_SHIFT) | (plspIdRaw[1] << FOUR_BITS_SHIFT) | (plspIdRaw[2] >> FOUR_BITS_SHIFT))));
         final BitSet flags = ByteArray.bytesToBitSet(ByteArray.readBytes(bytes, 2));
         builder.setDelegate(flags.get(DELEGATE_FLAG_OFFSET));
         builder.setSync(flags.get(SYNC_FLAG_OFFSET));
@@ -107,28 +113,28 @@ public class Stateful07LspObjectParser extends AbstractObjectWithTlvsParser<Tlvs
         final Lsp specObj = (Lsp) object;
         final ByteBuf body = Unpooled.buffer();
 
-        final byte[] retBytes = new byte[4];
+        final byte[] retBytes = new byte[BODY_LENGTH];
 
         Preconditions.checkArgument(specObj.getPlspId() != null, "PLSP-ID not present");
         final int lspID = specObj.getPlspId().getValue().intValue();
-        retBytes[0] = (byte) (lspID >> 12);
-        retBytes[1] = (byte) (lspID >> 4);
-        retBytes[2] = (byte) (lspID << 4);
+        retBytes[0] = (byte) (lspID >> TWELVE_BITS_SHIFT);
+        retBytes[1] = (byte) (lspID >> FOUR_BITS_SHIFT);
+        retBytes[2] = (byte) (lspID << FOUR_BITS_SHIFT);
         if (specObj.isDelegate() != null && specObj.isDelegate()) {
-            retBytes[3] |= 1 << (Byte.SIZE - (DELEGATE_FLAG_OFFSET - Byte.SIZE) - 1);
+            retBytes[FLAGS_INDEX] |= 1 << (Byte.SIZE - (DELEGATE_FLAG_OFFSET - Byte.SIZE) - 1);
         }
         if (specObj.isRemove() != null && specObj.isRemove()) {
-            retBytes[3] |= 1 << (Byte.SIZE - (REMOVE_FLAG_OFFSET - Byte.SIZE) - 1);
+            retBytes[FLAGS_INDEX] |= 1 << (Byte.SIZE - (REMOVE_FLAG_OFFSET - Byte.SIZE) - 1);
         }
         if (specObj.isSync() != null && specObj.isSync()) {
-            retBytes[3] |= 1 << (Byte.SIZE - (SYNC_FLAG_OFFSET - Byte.SIZE) - 1);
+            retBytes[FLAGS_INDEX] |= 1 << (Byte.SIZE - (SYNC_FLAG_OFFSET - Byte.SIZE) - 1);
         }
         if (specObj.isAdministrative() != null && specObj.isAdministrative()) {
-            retBytes[3] |= 1 << (Byte.SIZE - (ADMINISTRATIVE_FLAG_OFFSET - Byte.SIZE) - 1);
+            retBytes[FLAGS_INDEX] |= 1 << (Byte.SIZE - (ADMINISTRATIVE_FLAG_OFFSET - Byte.SIZE) - 1);
         }
         if (specObj.getOperational() != null) {
             final int op = specObj.getOperational().getIntValue();
-            retBytes[3] |= (op & 7) << 4;
+            retBytes[FLAGS_INDEX] |= (op & OP_VALUE_BITS_OFFSET) << FOUR_BITS_SHIFT;
         }
         body.writeBytes(retBytes);
         serializeTlvs(specObj.getTlvs(), body);
index 9b8fdb9471da72215dc53bd87804c0805a3c0505..cd63d91b7378dc584147b926575f22b889e744a8 100644 (file)
@@ -50,7 +50,6 @@ public final class PCEPDispatcherImplModule extends org.opendaylight.controller.
         Open localPrefs = getPcepSessionProposalFactoryDependency().getSessionProposal(null, 0);
         DefaultPCEPSessionNegotiatorFactory negFactory = new DefaultPCEPSessionNegotiatorFactory(localPrefs, getMaxUnknownMessages());
 
-        final PCEPDispatcherImpl instance = new PCEPDispatcherImpl(getPcepExtensionsDependency().getMessageHandlerRegistry(), negFactory, getBossGroupDependency(), getWorkerGroupDependency(), getMd5ChannelFactoryDependency(), getMd5ServerChannelFactoryDependency());
-        return instance;
+        return new PCEPDispatcherImpl(getPcepExtensionsDependency().getMessageHandlerRegistry(), negFactory, getBossGroupDependency(), getWorkerGroupDependency(), getMd5ChannelFactoryDependency(), getMd5ServerChannelFactoryDependency());
     }
 }
index 01d9c3b9956de4590eff253c2adefb4588417bb1..5739ad1767c4b3248b595179d03b5174b681b966 100644 (file)
@@ -59,8 +59,7 @@ public class PCEPSessionImpl extends AbstractProtocolSession<Message> implements
      */
     private long lastMessageReceivedAt;
 
-    @VisibleForTesting
-    protected final Queue<Long> unknownMessagesTimes = new LinkedList<Long>();
+    private final Queue<Long> unknownMessagesTimes = new LinkedList<Long>();
 
     private final PCEPSessionListener listener;
 
@@ -384,4 +383,9 @@ public class PCEPSessionImpl extends AbstractProtocolSession<Message> implements
     public String getNodeIdentifier() {
         return "";
     }
+
+    @VisibleForTesting
+    protected final Queue<Long> getUnknownMessagesTimes() {
+        return this.unknownMessagesTimes;
+    }
 }
index d1b87f855dde4916e055ffef656650bc20c9f0fd..35d95bc872db082d263e936919d34ab1c787366b 100644 (file)
@@ -339,8 +339,8 @@ public class PCEPRequestMessageParser extends AbstractMessageParser {
 
         if (rp.isReoptimization()
                 && builder.getBandwidth() != null
-                && builder.getReportedRoute().getBandwidth().getBandwidth() !=
-                new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.Bandwidth(new byte[] { 0 })
+                && !builder.getReportedRoute().getBandwidth().getBandwidth().equals(
+                        new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.Bandwidth(new byte[] { 0 }))
                 && builder.getReportedRoute().getRro() == null) {
             errors.add(createErrorMsg(PCEPErrors.RRO_MISSING, Optional.of(rp)));
             return null;
index ac2699cd06f10971ad791fae4439058888ea59a8..e8b8966419538e0c3c5aae6d411567e3590cedca 100644 (file)
@@ -216,28 +216,28 @@ public class FiniteStateMachineTest {
         final SimpleSessionListener client = new SimpleSessionListener();
         final PCEPSessionImpl s = new PCEPSessionImpl(client, 5, this.clientListener, this.openmsg.getOpenMessage().getOpen(), this.openmsg.getOpenMessage().getOpen());
         s.handleMalformedMessage(PCEPErrors.CAPABILITY_NOT_SUPPORTED);
-        assertEquals(1, s.unknownMessagesTimes.size());
+        assertEquals(1, s.getUnknownMessagesTimes().size());
         Thread.sleep(10000);
         s.handleMalformedMessage(PCEPErrors.CAPABILITY_NOT_SUPPORTED);
-        assertEquals(2, s.unknownMessagesTimes.size());
+        assertEquals(2, s.getUnknownMessagesTimes().size());
         Thread.sleep(10000);
         s.handleMalformedMessage(PCEPErrors.CAPABILITY_NOT_SUPPORTED);
-        assertEquals(3, s.unknownMessagesTimes.size());
+        assertEquals(3, s.getUnknownMessagesTimes().size());
         Thread.sleep(20000);
         s.handleMalformedMessage(PCEPErrors.CAPABILITY_NOT_SUPPORTED);
-        assertEquals(4, s.unknownMessagesTimes.size());
+        assertEquals(4, s.getUnknownMessagesTimes().size());
         Thread.sleep(30000);
         s.handleMalformedMessage(PCEPErrors.CAPABILITY_NOT_SUPPORTED);
-        assertEquals(3, s.unknownMessagesTimes.size());
+        assertEquals(3, s.getUnknownMessagesTimes().size());
         Thread.sleep(10000);
         s.handleMalformedMessage(PCEPErrors.CAPABILITY_NOT_SUPPORTED);
-        assertEquals(3, s.unknownMessagesTimes.size());
+        assertEquals(3, s.getUnknownMessagesTimes().size());
         Thread.sleep(5000);
         s.handleMalformedMessage(PCEPErrors.CAPABILITY_NOT_SUPPORTED);
-        assertEquals(4, s.unknownMessagesTimes.size());
+        assertEquals(4, s.getUnknownMessagesTimes().size());
         Thread.sleep(1000);
         s.handleMalformedMessage(PCEPErrors.CAPABILITY_NOT_SUPPORTED);
-        assertEquals(5, s.unknownMessagesTimes.size());
+        assertEquals(5, s.getUnknownMessagesTimes().size());
         Thread.sleep(1000);
         s.handleMalformedMessage(PCEPErrors.CAPABILITY_NOT_SUPPORTED);
         synchronized (client) {
index d638fa98705189ea1e3e9d5ceff5177a0a6b1e5b..52f008a33cff29a8ad50acb9ed27d891cc42d3c7 100644 (file)
@@ -8,7 +8,7 @@
 
 package org.opendaylight.protocol.pcep.spi;
 
-public class VendorInformationUtil {
+public final class VendorInformationUtil {
 
     public static final int VENDOR_INFORMATION_TLV_TYPE = 7;
 
index bed72e8d9917ff83edcc53e11a41be984fe357fd..54d03551a362530e6cca0012233ed9be92971c4e 100644 (file)
@@ -10,6 +10,8 @@ package org.opendaylight.protocol.pcep.testtool;
 import io.netty.channel.nio.NioEventLoopGroup;
 import java.net.InetAddress;
 import java.net.InetSocketAddress;
+import java.net.UnknownHostException;
+import java.util.concurrent.ExecutionException;
 import org.opendaylight.protocol.pcep.PCEPSessionProposalFactory;
 import org.opendaylight.protocol.pcep.ietf.initiated00.Stateful07SessionProposalFactory;
 import org.opendaylight.protocol.pcep.ietf.stateful07.StatefulActivator;
@@ -64,7 +66,7 @@ public final class Main {
 
     }
 
-    public static void main(final String[] args) throws Exception {
+    public static void main(final String[] args) throws NumberFormatException, UnknownHostException, InterruptedException, ExecutionException {
         if (args.length == 0 || (args.length == 1 && args[0].equalsIgnoreCase("--help"))) {
             LOG.info(Main.USAGE);
             return;
@@ -75,7 +77,6 @@ public final class Main {
         int deadTimerValue = 0;
         boolean stateful = false;
         boolean active = false;
-        final boolean versioned = false;
         boolean instant = false;
 
         int i = 0;
@@ -114,11 +115,12 @@ public final class Main {
 
         final Open prefs = spf.getSessionProposal(address, 0);
 
-        final StatefulActivator activator07 = new StatefulActivator();
-        activator07.start(ServiceLoaderPCEPExtensionProviderContext.getSingletonInstance());
+        try (final StatefulActivator activator07 = new StatefulActivator()) {
+            activator07.start(ServiceLoaderPCEPExtensionProviderContext.getSingletonInstance());
 
-        final PCEPDispatcherImpl dispatcher = new PCEPDispatcherImpl(ServiceLoaderPCEPExtensionProviderContext.getSingletonInstance().getMessageHandlerRegistry(), new DefaultPCEPSessionNegotiatorFactory(prefs, 5), new NioEventLoopGroup(), new NioEventLoopGroup());
+            final PCEPDispatcherImpl dispatcher = new PCEPDispatcherImpl(ServiceLoaderPCEPExtensionProviderContext.getSingletonInstance().getMessageHandlerRegistry(), new DefaultPCEPSessionNegotiatorFactory(prefs, 5), new NioEventLoopGroup(), new NioEventLoopGroup());
 
-        dispatcher.createServer(address, new TestingSessionListenerFactory()).get();
+            dispatcher.createServer(address, new TestingSessionListenerFactory()).get();
+        }
     }
 }
index eba5f14f5fe216ecc1003d8415b4b662ce9dbeef..f655da86834859d3668c0313feaf8f30caf41990 100644 (file)
@@ -8,9 +8,7 @@
 package org.opendaylight.protocol.pcep.testtool;
 
 import com.google.common.collect.Lists;
-
 import java.util.List;
-
 import org.opendaylight.protocol.pcep.PCEPSession;
 import org.opendaylight.protocol.pcep.PCEPSessionListener;
 import org.opendaylight.protocol.pcep.PCEPTerminationReason;
@@ -23,7 +21,7 @@ import org.slf4j.LoggerFactory;
  */
 public class SimpleSessionListener implements PCEPSessionListener {
 
-    public List<Message> messages = Lists.newArrayList();
+    private List<Message> messages = Lists.newArrayList();
 
     private static final Logger LOG = LoggerFactory.getLogger(SimpleSessionListener.class);
 
index d16d4221857cdba6161cf16c6da480e944bd0e12..0599d6ad94bdff7ee210c703c90cbc26a7e3b8d8 100644 (file)
@@ -8,9 +8,7 @@
 package org.opendaylight.protocol.pcep.testtool;
 
 import com.google.common.collect.Lists;
-
 import java.util.List;
-
 import org.opendaylight.protocol.pcep.PCEPSession;
 import org.opendaylight.protocol.pcep.PCEPSessionListener;
 import org.opendaylight.protocol.pcep.PCEPTerminationReason;
@@ -22,7 +20,7 @@ public class TestingSessionListener implements PCEPSessionListener {
 
     private final List<Message> messages = Lists.newArrayList();
 
-    public boolean up = false;
+    private boolean up = false;
 
     private static final Logger LOG = LoggerFactory.getLogger(TestingSessionListener.class);
 
@@ -55,4 +53,8 @@ public class TestingSessionListener implements PCEPSessionListener {
     public List<Message> messages() {
         return this.messages;
     }
+
+    public boolean isUp () {
+        return this.up;
+    }
 }
index 07c9146d81b1392072279e725dda6f0e4fe11e2f..6adf0da8787ff7e10db4e003100d94661dc71344 100644 (file)
@@ -25,10 +25,10 @@ public class PCEPTestingToolTest {
         ssl.onMessage(null, new KeepaliveBuilder().setKeepaliveMessage(new KeepaliveMessageBuilder().build()).build());
         assertEquals(1, ssl.messages().size());
         assertTrue(ssl.messages().get(0) instanceof KeepaliveMessage);
-        assertFalse(ssl.up);
+        assertFalse(ssl.isUp());
         ssl.onSessionUp(null);
-        assertTrue(ssl.up);
+        assertTrue(ssl.isUp());
         ssl.onSessionDown(null, null);
-        assertFalse(ssl.up);
+        assertFalse(ssl.isUp());
     }
 }
index 68a4f04fc4ec69a7f1923570b17758562a5100ba..3151db0217ee172cb59e8213bdbaf17a3432cbe0 100644 (file)
@@ -99,6 +99,8 @@ public abstract class AbstractTopologySessionListener<S, L> implements PCEPSessi
     };
     private static final Logger LOG = LoggerFactory.getLogger(AbstractTopologySessionListener.class);
 
+    protected static final String MISSING_XML_TAG = "Mandatory XML tags are missing.";
+
     @GuardedBy("this")
     private final Map<S, PCEPRequest> requests = new HashMap<>();
 
index c46c685463fb66fd760d1e93e6c7580baf90cdab..4c30187c6ec23bd384cac3d4faec85a3c249934c 100644 (file)
@@ -155,7 +155,7 @@ public class Stateful02TopologySessionListener extends AbstractTopologySessionLi
 
     @Override
     public synchronized ListenableFuture<OperationResult> addLsp(final AddLspArgs input) {
-        Preconditions.checkArgument(input != null && input.getName() != null && input.getNode() != null && input.getArguments() != null, "Mandatory XML tags are missing.");
+        Preconditions.checkArgument(input != null && input.getName() != null && input.getNode() != null && input.getArguments() != null, MISSING_XML_TAG);
         // Make sure there is no such LSP
         final InstanceIdentifier<ReportedLsp> lsp = lspIdentifier(input.getName());
         final ListenableFuture<Optional<ReportedLsp>> f = readOperationalData(lsp);
@@ -191,7 +191,7 @@ public class Stateful02TopologySessionListener extends AbstractTopologySessionLi
 
     @Override
     public synchronized ListenableFuture<OperationResult> removeLsp(final RemoveLspArgs input) {
-        Preconditions.checkArgument(input != null && input.getName() != null && input.getNode() != null, "Mandatory XML tags are missing.");
+        Preconditions.checkArgument(input != null && input.getName() != null && input.getNode() != null, MISSING_XML_TAG);
         // Make sure the LSP exists, we need it for PLSP-ID
         final InstanceIdentifier<ReportedLsp> lsp = lspIdentifier(input.getName());
         final ListenableFuture<Optional<ReportedLsp>> f = readOperationalData(lsp);
@@ -222,7 +222,7 @@ public class Stateful02TopologySessionListener extends AbstractTopologySessionLi
 
     @Override
     public synchronized ListenableFuture<OperationResult> updateLsp(final UpdateLspArgs input) {
-        Preconditions.checkArgument(input != null && input.getName() != null && input.getNode() != null && input.getArguments() != null, "Mandatory XML tags are missing.");
+        Preconditions.checkArgument(input != null && input.getName() != null && input.getNode() != null && input.getArguments() != null, MISSING_XML_TAG);
         // Make sure the LSP exists
         final InstanceIdentifier<ReportedLsp> lsp = lspIdentifier(input.getName());
         final ListenableFuture<Optional<ReportedLsp>> f = readOperationalData(lsp);
@@ -258,7 +258,7 @@ public class Stateful02TopologySessionListener extends AbstractTopologySessionLi
 
     @Override
     public synchronized ListenableFuture<OperationResult> ensureLspOperational(final EnsureLspOperationalInput input) {
-        Preconditions.checkArgument(input != null && input.getName() != null && input.getNode() != null && input.getArguments() != null, "Mandatory XML tags are missing.");
+        Preconditions.checkArgument(input != null && input.getName() != null && input.getNode() != null && input.getArguments() != null, MISSING_XML_TAG);
         final Boolean op;
         final Arguments1 aa = input.getArguments().getAugmentation(Arguments1.class);
         if (aa == null) {
index 506097499b190350b516af4825c75ff3d74e4556..f6a41aa5c4bc9fa05607ff1f33624afcbb62ff06 100644 (file)
@@ -74,6 +74,7 @@ import org.slf4j.LoggerFactory;
 
 final class Stateful07TopologySessionListener extends AbstractTopologySessionListener<SrpIdNumber, PlspId> {
     private static final Logger LOG = LoggerFactory.getLogger(Stateful07TopologySessionListener.class);
+
     private final AtomicLong requestId = new AtomicLong(1L);
 
     /**
@@ -211,7 +212,7 @@ final class Stateful07TopologySessionListener extends AbstractTopologySessionLis
 
     @Override
     public synchronized ListenableFuture<OperationResult> addLsp(final AddLspArgs input) {
-        Preconditions.checkArgument(input != null && input.getName() != null && input.getNode() != null && input.getArguments() != null, "Mandatory XML tags are missing.");
+        Preconditions.checkArgument(input != null && input.getName() != null && input.getNode() != null && input.getArguments() != null, MISSING_XML_TAG);
         LOG.trace("AddLspArgs {}", input);
         // Make sure there is no such LSP
         final InstanceIdentifier<ReportedLsp> lsp = lspIdentifier(input.getName());
@@ -257,7 +258,7 @@ final class Stateful07TopologySessionListener extends AbstractTopologySessionLis
 
     @Override
     public synchronized ListenableFuture<OperationResult> removeLsp(final RemoveLspArgs input) {
-        Preconditions.checkArgument(input != null && input.getName() != null && input.getNode() != null, "Mandatory XML tags are missing.");
+        Preconditions.checkArgument(input != null && input.getName() != null && input.getNode() != null, MISSING_XML_TAG);
         LOG.trace("RemoveLspArgs {}", input);
         // Make sure the LSP exists, we need it for PLSP-ID
         final InstanceIdentifier<ReportedLsp> lsp = lspIdentifier(input.getName());
@@ -291,7 +292,7 @@ final class Stateful07TopologySessionListener extends AbstractTopologySessionLis
 
     @Override
     public synchronized ListenableFuture<OperationResult> updateLsp(final UpdateLspArgs input) {
-        Preconditions.checkArgument(input != null && input.getName() != null && input.getNode() != null && input.getArguments() != null, "Mandatory XML tags are missing.");
+        Preconditions.checkArgument(input != null && input.getName() != null && input.getNode() != null && input.getArguments() != null, MISSING_XML_TAG);
         LOG.trace("UpdateLspArgs {}", input);
         // Make sure the LSP exists
         final InstanceIdentifier<ReportedLsp> lsp = lspIdentifier(input.getName());
@@ -353,7 +354,7 @@ final class Stateful07TopologySessionListener extends AbstractTopologySessionLis
 
     @Override
     public synchronized ListenableFuture<OperationResult> ensureLspOperational(final EnsureLspOperationalInput input) {
-        Preconditions.checkArgument(input != null && input.getName() != null && input.getNode() != null && input.getArguments() != null, "Mandatory XML tags are missing.");
+        Preconditions.checkArgument(input != null && input.getName() != null && input.getNode() != null && input.getArguments() != null, MISSING_XML_TAG);
         final OperationalStatus op;
         final Arguments1 aa = input.getArguments().getAugmentation(Arguments1.class);
         if (aa != null) {
index f34e78465bc17e0019091b8f51ac08f19e08026e..21d00e788f93c6b5458bee1192237ebe417db4c0 100644 (file)
@@ -40,6 +40,8 @@ public final class PCEPTopologyProviderModule extends
         org.opendaylight.controller.config.yang.pcep.topology.provider.AbstractPCEPTopologyProviderModule {
     private static final Logger LOG = LoggerFactory.getLogger(PCEPTopologyProviderModule.class);
 
+    private static final String IS_NOT_SET = "is not set.";
+
     public PCEPTopologyProviderModule(final org.opendaylight.controller.config.api.ModuleIdentifier identifier,
             final org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
         super(identifier, dependencyResolver);
@@ -83,10 +85,10 @@ public final class PCEPTopologyProviderModule extends
 
     @Override
     public void customValidation() {
-        JmxAttributeValidationException.checkNotNull(getTopologyId(), "is not set.", topologyIdJmxAttribute);
-        JmxAttributeValidationException.checkNotNull(getListenAddress(), "is not set.", listenAddressJmxAttribute);
-        JmxAttributeValidationException.checkNotNull(getListenPort(), "is not set.", listenPortJmxAttribute);
-        JmxAttributeValidationException.checkNotNull(getStatefulPlugin(), "is not set.", statefulPluginJmxAttribute);
+        JmxAttributeValidationException.checkNotNull(getTopologyId(), IS_NOT_SET, topologyIdJmxAttribute);
+        JmxAttributeValidationException.checkNotNull(getListenAddress(), IS_NOT_SET, listenAddressJmxAttribute);
+        JmxAttributeValidationException.checkNotNull(getListenPort(), IS_NOT_SET, listenPortJmxAttribute);
+        JmxAttributeValidationException.checkNotNull(getStatefulPlugin(), IS_NOT_SET, statefulPluginJmxAttribute);
 
         final KeyMapping keys = contructKeys();
         if (!keys.isEmpty()) {
index 4f73a4d9d5fce83f452a4ca777a61606389ee1da..3962fe810a3cfce89c742ea47e24407a55004012 100644 (file)
@@ -19,9 +19,7 @@ package org.opendaylight.controller.config.yang.programming.impl;
 import com.google.common.util.concurrent.ListenableFuture;
 import com.google.common.util.concurrent.ListeningExecutorService;
 import com.google.common.util.concurrent.MoreExecutors;
-
 import java.util.concurrent.Executors;
-
 import org.opendaylight.bgpcep.programming.impl.ProgrammingServiceImpl;
 import org.opendaylight.bgpcep.programming.spi.Instruction;
 import org.opendaylight.bgpcep.programming.spi.InstructionScheduler;
@@ -62,7 +60,7 @@ public final class InstructionSchedulerImplModule extends
 
         final class ProgrammingServiceImplCloseable implements InstructionScheduler, AutoCloseable {
             @Override
-            public void close() throws Exception {
+            public void close() {
                 try {
                     reg.close();
                 } finally {
index bd58afae1eb59e88b7c4df7951fb7370a0b44d84..83713c3420512a922773117f6954c32b0be81d65 100644 (file)
@@ -91,8 +91,7 @@ public final class ByteArray {
      * @return a new byte array that is a sub-array of the original
      */
     public static byte[] subByte(final byte[] bytes, final int startIndex, final int length) {
-        if (bytes.length == 0 || length < 0 || length > bytes.length || startIndex < 0 || startIndex > bytes.length
-            || startIndex + length > bytes.length) {
+        if (!checkLength(bytes, length) || !checkStartIndex(bytes, startIndex, length)) {
             throw new IllegalArgumentException("Cannot create subByte, invalid arguments: Length: " + length + " startIndex: " + startIndex);
         }
         final byte[] res = new byte[length];
@@ -100,6 +99,14 @@ public final class ByteArray {
         return res;
     }
 
+    private static boolean checkLength(final byte[] bytes, final int length) {
+        return length > 0 && bytes.length > 0 && length <= bytes.length;
+    }
+
+    private static boolean checkStartIndex(final byte[] bytes, final int startIndex, final int length) {
+        return startIndex >= 0 && startIndex < bytes.length && (startIndex + length <= bytes.length);
+    }
+
     /**
      * Converts byte array to Integer. If there are less bytes in the array as required (4), the method will push
      * adequate number of zero bytes prepending given byte array.