BUG-731 : fixed pcep sonar warnings 58/12158/1
authorDana Kutenicsova <dkutenic@cisco.com>
Wed, 22 Oct 2014 13:24:26 +0000 (15:24 +0200)
committerDana Kutenicsova <dkutenic@cisco.com>
Wed, 22 Oct 2014 13:24:26 +0000 (15:24 +0200)
Change-Id: I2cb38fb5b6546d55c0c08b01cd428eb35646747e
Signed-off-by: Dana Kutenicsova <dkutenic@cisco.com>
18 files changed:
pcep/ietf-stateful07/src/main/java/org/opendaylight/protocol/pcep/ietf/stateful07/Stateful07RSVPErrorSpecTlvParser.java
pcep/impl/src/main/java/org/opendaylight/controller/config/yang/pcep/impl/PCEPSessionProposalFactoryImplModule.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/PCEPByteToMessageDecoder.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/PCEPSessionImpl.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/AbstractEROWithSubobjectsParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/AbstractXROWithSubobjectsParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPClassTypeObjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPMetricObjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/subobject/EROExplicitExclusionRouteSubobjectParser.java
pcep/pcc-mock/src/main/java/org/opendaylight/protocol/pcep/pcc/mock/Main.java
pcep/pcc-mock/src/main/java/org/opendaylight/protocol/pcep/pcc/mock/PCCMock.java
pcep/segment-routing/src/main/java/org/opendaylight/protocol/pcep/segment/routing02/SrEroUtil.java
pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/PCEPErrors.java
pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/pojo/SimpleObjectRegistry.java
pcep/testtool/src/main/java/org/opendaylight/protocol/pcep/testtool/Main.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/ServerSessionManager.java
util/src/main/java/org/opendaylight/protocol/util/Values.java

index f60af72215dc59e03db174e262e70b9d145f420a..908ba1f2dfcb3418a27e29e177c1ecaaeb0a687d 100644 (file)
@@ -14,6 +14,7 @@ import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedByte;
 import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedInt;
 import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedShort;
 
+import com.google.common.base.Charsets;
 import com.google.common.base.Preconditions;
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
@@ -107,7 +108,7 @@ public final class Stateful07RSVPErrorSpecTlvParser implements TlvParser, TlvSer
     }
 
     private void serializerUserError(final UserError ue, final ByteBuf body) {
-        byte[] desc = (ue.getDescription() == null) ? new byte[0] : ue.getDescription().getBytes();
+        final byte[] desc = (ue.getDescription() == null) ? new byte[0] : ue.getDescription().getBytes(Charsets.UTF_8);
         final ByteBuf userErrorBuf = Unpooled.buffer();
         Preconditions.checkArgument(ue.getEnterprise() != null, "EnterpriseNumber is mandatory");
         writeUnsignedInt(ue.getEnterprise().getValue(), userErrorBuf);
index 36866ed6ab1bdff156891d6bb73f97848cd80f4d..c94ec25a59622a5f8df26d13eb151cb2a1dca989 100644 (file)
@@ -17,7 +17,6 @@
 package org.opendaylight.controller.config.yang.pcep.impl;
 
 import java.net.InetSocketAddress;
-
 import org.opendaylight.controller.config.api.JmxAttributeValidationException;
 import org.opendaylight.protocol.pcep.PCEPSessionProposalFactory;
 import org.opendaylight.protocol.pcep.impl.BasePCEPSessionProposalFactory;
@@ -33,6 +32,8 @@ public final class PCEPSessionProposalFactoryImplModule extends
 
     private static final Logger LOG = LoggerFactory.getLogger(PCEPSessionProposalFactoryImplModule.class);
 
+    private static final int KA_TO_DEADTIMER_RATIO = 4;
+
     public PCEPSessionProposalFactoryImplModule(final org.opendaylight.controller.config.api.ModuleIdentifier name,
             final org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
         super(name, dependencyResolver);
@@ -51,7 +52,7 @@ public final class PCEPSessionProposalFactoryImplModule extends
         if (getKeepAliveTimerValue() != 0) {
             JmxAttributeValidationException.checkCondition(getKeepAliveTimerValue() >= 1, "minimum value is 1.",
                     keepAliveTimerValueJmxAttribute);
-            if (getDeadTimerValue() != 0 && (getDeadTimerValue() / getKeepAliveTimerValue() != 4)) {
+            if (getDeadTimerValue() != 0 && (getDeadTimerValue() / getKeepAliveTimerValue() != KA_TO_DEADTIMER_RATIO)) {
                 LOG.warn("DeadTimerValue should be 4 times greater than KeepAliveTimerValue");
             }
         }
index f6255c2a4342c004d7f6782b79dd74b381dc3f07..a545aafa5a8c3af3c24db6b96ac2071a6fa3598e 100644 (file)
@@ -8,15 +8,12 @@
 package org.opendaylight.protocol.pcep.impl;
 
 import com.google.common.base.Preconditions;
-
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.ByteBufUtil;
 import io.netty.channel.ChannelHandlerContext;
 import io.netty.handler.codec.ByteToMessageDecoder;
-
 import java.util.ArrayList;
 import java.util.List;
-
 import org.opendaylight.protocol.pcep.spi.MessageRegistry;
 import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
 import org.opendaylight.protocol.pcep.spi.PCEPMessageConstants;
@@ -37,7 +34,7 @@ public final class PCEPByteToMessageDecoder extends ByteToMessageDecoder {
     }
 
     @Override
-    protected void decode(final ChannelHandlerContext ctx, final ByteBuf in, final List<Object> out) throws Exception {
+    protected void decode(final ChannelHandlerContext ctx, final ByteBuf in, final List<Object> out) {
         if (!in.isReadable()) {
             LOG.debug("No more content in incoming buffer.");
             return;
@@ -52,7 +49,6 @@ public final class PCEPByteToMessageDecoder extends ByteToMessageDecoder {
             out.add(parse(in, errors));
         } catch (final PCEPDeserializerException e) {
             LOG.debug("Failed to decode protocol message", e);
-            this.exceptionCaught(ctx, e);
         }
         in.discardReadBytes();
 
index a4aed7154d38d55091af687b12f9617576424668..a8af7ba16145d222be45dbd8ff58e249ad0309a1 100644 (file)
@@ -127,11 +127,11 @@ public class PCEPSessionImpl extends AbstractProtocolSession<Message> implements
         this.sessionState = new PCEPSessionState(remoteOpen, localOpen, channel);
     }
 
-    public Integer getKeepAliveTimerValue() {
+    public final Integer getKeepAliveTimerValue() {
         return this.localOpen.getKeepalive().intValue();
     }
 
-    public Integer getDeadTimerValue() {
+    public final Integer getDeadTimerValue() {
         return this.remoteOpen.getDeadTimer().intValue();
     }
 
index 96fd9b369080f1175c236413af2c06e218d259bd..b4939983d618d6512c82890c16287b4032b274e6 100644 (file)
@@ -17,6 +17,7 @@ import org.opendaylight.protocol.pcep.spi.EROSubobjectRegistry;
 import org.opendaylight.protocol.pcep.spi.ObjectParser;
 import org.opendaylight.protocol.pcep.spi.ObjectSerializer;
 import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
+import org.opendaylight.protocol.util.Values;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.ero.Subobject;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -38,9 +39,9 @@ public abstract class AbstractEROWithSubobjectsParser implements ObjectParser, O
         Preconditions.checkArgument(buffer != null, "Array of bytes is mandatory. Can't be null.");
         final List<Subobject> subs = new ArrayList<>();
         while (buffer.isReadable()) {
-            boolean loose = ((buffer.getByte(buffer.readerIndex()) & (1 << 7)) != 0) ? true : false;
-            int type = (buffer.readByte() & 0xff) & ~(1 << 7);
-            int length = UnsignedBytes.toInt(buffer.readByte()) - HEADER_LENGTH;
+            final boolean loose = ((buffer.getByte(buffer.readerIndex()) & (1 << Values.FIRST_BIT_OFFSET)) != 0) ? true : false;
+            final int type = (buffer.readByte() & Values.BYTE_MAX_VALUE_BYTES) & ~(1 << Values.FIRST_BIT_OFFSET);
+            final int length = UnsignedBytes.toInt(buffer.readByte()) - HEADER_LENGTH;
             if (length > buffer.readableBytes()) {
                 throw new PCEPDeserializerException("Wrong length specified. Passed: " + length + "; Expected: <= "
                         + buffer.readableBytes());
index 987f25a40f41b1f8f91a0f01b7f2b8aeb54619b3..290c6c14c5ac068eac832fcd37c20da9644bbbe2 100644 (file)
@@ -17,6 +17,7 @@ import org.opendaylight.protocol.pcep.spi.ObjectParser;
 import org.opendaylight.protocol.pcep.spi.ObjectSerializer;
 import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
 import org.opendaylight.protocol.pcep.spi.XROSubobjectRegistry;
+import org.opendaylight.protocol.util.Values;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.exclude.route.object.xro.Subobject;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -37,9 +38,9 @@ public abstract class AbstractXROWithSubobjectsParser implements ObjectParser, O
         Preconditions.checkArgument(buffer != null && buffer.isReadable(), "Array of bytes is mandatory. Can't be null or empty.");
         final List<Subobject> subs = new ArrayList<>();
         while (buffer.isReadable()) {
-            final boolean mandatory = ((buffer.getByte(buffer.readerIndex()) & (1 << 7)) != 0) ? true : false;
-            int type = UnsignedBytes.checkedCast((buffer.readByte() & 0xff) & ~(1 << 7));
-            int length = UnsignedBytes.toInt(buffer.readByte()) - HEADER_LENGTH;
+            final boolean mandatory = ((buffer.getByte(buffer.readerIndex()) & (1 << Values.FIRST_BIT_OFFSET)) != 0) ? true : false;
+            final int type = UnsignedBytes.checkedCast((buffer.readByte() & Values.BYTE_MAX_VALUE_BYTES) & ~(1 << Values.FIRST_BIT_OFFSET));
+            final int length = UnsignedBytes.toInt(buffer.readByte()) - HEADER_LENGTH;
             if (length > buffer.readableBytes()) {
                 throw new PCEPDeserializerException("Wrong length specified. Passed: " + length + "; Expected: <= "
                         + buffer.readableBytes());
index 332919a22a6eee11c031fe935bc799d00e9ca184..42195ea41bf54e63bbf1b0fddcfca02a2456f697 100644 (file)
@@ -70,7 +70,7 @@ public class PCEPClassTypeObjectParser implements ObjectParser, ObjectSerializer
         builder.setClassType(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ClassType(ct));
 
         final Object obj = builder.build();
-        if (ct < 0 || ct > 8) {
+        if (ct < 0 || ct > Byte.SIZE) {
             LOG.debug("Invalid class type {}", ct);
             return new UnknownObject(PCEPErrors.INVALID_CT, obj);
         }
index c976f346b6ff2f6de7d306e3d7ef30a5fe939703..f2f3e220a322e1cfea77b1ca0fa658006d5cf916 100644 (file)
@@ -53,7 +53,7 @@ public class PCEPMetricObjectParser implements ObjectParser, ObjectSerializer {
     private static final int C_FLAG_OFFSET = 6;
     private static final int B_FLAG_OFFSET = 7;
 
-    private static final int SIZE = 4 + METRIC_VALUE_F_LENGTH;
+    private static final int SIZE = METRIC_VALUE_F_LENGTH + METRIC_VALUE_F_LENGTH;
 
     @Override
     public Metric parseObject(final ObjectHeader header, final ByteBuf bytes) throws PCEPDeserializerException {
index 31e323990c3c2ba70fc287cd70596f879a4c9461..cf1bc443b1041f4e1ed17ddfd5b774479d633f43 100644 (file)
@@ -10,18 +10,16 @@ package org.opendaylight.protocol.pcep.impl.subobject;
 import com.google.common.base.Preconditions;
 import com.google.common.collect.Lists;
 import com.google.common.primitives.UnsignedBytes;
-
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
-
 import java.util.ArrayList;
 import java.util.List;
-
 import org.opendaylight.protocol.pcep.spi.EROSubobjectParser;
 import org.opendaylight.protocol.pcep.spi.EROSubobjectSerializer;
 import org.opendaylight.protocol.pcep.spi.EROSubobjectUtil;
 import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
 import org.opendaylight.protocol.pcep.spi.XROSubobjectRegistry;
+import org.opendaylight.protocol.util.Values;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.ero.Subobject;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.ero.SubobjectBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.explicit.route.subobjects.subobject.type.ExrsCase;
@@ -81,9 +79,9 @@ public class EROExplicitExclusionRouteSubobjectParser implements EROSubobjectPar
         Preconditions.checkArgument(buffer != null && buffer.isReadable(), "Array of bytes is mandatory. Can't be null or empty.");
         final List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.exclude.route.object.xro.Subobject> subs = new ArrayList<>();
         while (buffer.isReadable()) {
-            final boolean mandatory = ((buffer.getByte(buffer.readerIndex()) & (1 << 7)) != 0) ? true : false;
-            int type = (buffer.readByte() & 0xff) & ~(1 << 7);
-            int length = UnsignedBytes.toInt(buffer.readByte()) - HEADER_LENGTH;
+            final boolean mandatory = ((buffer.getByte(buffer.readerIndex()) & (1 << Values.FIRST_BIT_OFFSET)) != 0) ? true : false;
+            final int type = (buffer.readByte() & Values.BYTE_MAX_VALUE_BYTES) & ~(1 << Values.FIRST_BIT_OFFSET);
+            final int length = UnsignedBytes.toInt(buffer.readByte()) - HEADER_LENGTH;
             if (length > buffer.readableBytes()) {
                 throw new PCEPDeserializerException("Wrong length specified. Passed: " + length + "; Expected: <= "
                         + buffer.readableBytes());
index d7d17178cd44d0411c255a695fdff1ac2be6a6b4..dbb0915a894197b0401869d5409c9f532ddc7e10 100644 (file)
@@ -13,7 +13,6 @@ import ch.qos.logback.classic.LoggerContext;
 import com.google.common.base.Predicate;
 import com.google.common.collect.Iterables;
 import com.google.common.net.InetAddresses;
-import io.netty.util.concurrent.DefaultPromise;
 import io.netty.util.concurrent.GlobalEventExecutor;
 import java.net.InetAddress;
 import java.net.InetSocketAddress;
@@ -42,7 +41,9 @@ public final class Main {
     private static final short DEFAULT_DEAD_TIMER = 120;
     private static final int RECONNECT_STRATEGY_TIMEOUT = 2000;
 
-    public static void main(String[] args) throws InterruptedException, ExecutionException, UnknownHostException {
+    private Main() { }
+
+    public static void main(final String[] args) throws InterruptedException, ExecutionException, UnknownHostException {
         InetAddress localAddress = InetAddress.getByName("127.0.0.1");
         InetAddress remoteAddress = InetAddress.getByName("127.0.0.1");
         int pccCount = 1;
@@ -83,8 +84,7 @@ public final class Main {
         activator07.start(ServiceLoaderPCEPExtensionProviderContext.getSingletonInstance());
         activator.start(ServiceLoaderPCEPExtensionProviderContext.getSingletonInstance());
         final PCCMock<Message, PCEPSessionImpl, PCEPSessionListener> pcc = new PCCMock<>(snf, new PCEPHandlerFactory(
-                ServiceLoaderPCEPExtensionProviderContext.getSingletonInstance().getMessageHandlerRegistry()),
-                new DefaultPromise<PCEPSessionImpl>(GlobalEventExecutor.INSTANCE));
+                ServiceLoaderPCEPExtensionProviderContext.getSingletonInstance().getMessageHandlerRegistry()));
 
         final InetAddress pceAddress = remoteAddress;
         InetAddress currentAddress = localAddress;
@@ -108,8 +108,8 @@ public final class Main {
     private static ch.qos.logback.classic.Logger getRootLogger(final LoggerContext lc) {
         return Iterables.find(lc.getLoggerList(), new Predicate<Logger>() {
             @Override
-            public boolean apply(Logger input) {
-                return input.getName().equals(Logger.ROOT_LOGGER_NAME);
+            public boolean apply(final Logger input) {
+                return (input != null) ? input.getName().equals(Logger.ROOT_LOGGER_NAME) : false;
             }
         });
     }
index ca82baf2e51390b68a447ed743d8fda80ba162da..0715c184a152df3faae1354c38b943e44dc18f8a 100644 (file)
@@ -11,7 +11,6 @@ package org.opendaylight.protocol.pcep.pcc.mock;
 import com.google.common.base.Preconditions;
 import io.netty.channel.nio.NioEventLoopGroup;
 import io.netty.channel.socket.SocketChannel;
-import io.netty.util.concurrent.DefaultPromise;
 import io.netty.util.concurrent.Future;
 import io.netty.util.concurrent.GlobalEventExecutor;
 import io.netty.util.concurrent.Promise;
@@ -22,15 +21,13 @@ import org.opendaylight.protocol.framework.SessionListener;
 import org.opendaylight.protocol.framework.SessionListenerFactory;
 import org.opendaylight.protocol.framework.SessionNegotiatorFactory;
 import org.opendaylight.protocol.pcep.impl.PCEPHandlerFactory;
-import org.opendaylight.protocol.pcep.impl.PCEPSessionImpl;
 
 public class PCCMock<M, S extends ProtocolSession<M>, L extends SessionListener<M, ?, ?>> extends BindableDispatcher<S, L> {
 
     private final SessionNegotiatorFactory<M, S, L> negotiatorFactory;
     private final PCEPHandlerFactory factory;
 
-    public PCCMock(final SessionNegotiatorFactory<M, S, L> negotiatorFactory, final PCEPHandlerFactory factory,
-            final DefaultPromise<PCEPSessionImpl> defaultPromise) {
+    public PCCMock(final SessionNegotiatorFactory<M, S, L> negotiatorFactory, final PCEPHandlerFactory factory) {
         super(GlobalEventExecutor.INSTANCE, new NioEventLoopGroup(), new NioEventLoopGroup());
         this.negotiatorFactory = Preconditions.checkNotNull(negotiatorFactory);
         this.factory = Preconditions.checkNotNull(factory);
index 6f0b5515aec25e0c8c54fd2c18e427069014d0dc..efd369046bcbd2c83680ec464933775c9ac53a02 100644 (file)
@@ -35,10 +35,8 @@ public final class SrEroUtil {
                     return PCEPErrors.NON_IDENTICAL_ERO_SUBOBJECTS;
                 }
                 final SrEroSubobject srEroSubobject = (SrEroSubobject) subobject.getSubobjectType();
-                if (srEroSubobject.getFlags() != null) {
-                    if (srEroSubobject.getFlags().isM() && srEroSubobject.getSid() < MPLS_LABEL_MIN_VALUE) {
-                        return PCEPErrors.BAD_LABEL_VALUE;
-                    }
+                if (srEroSubobject.getFlags() != null && srEroSubobject.getFlags().isM() && srEroSubobject.getSid() < MPLS_LABEL_MIN_VALUE) {
+                    return PCEPErrors.BAD_LABEL_VALUE;
                 }
             }
         }
index 252399ac9a366a9fff73452e51fc2b36a362c44b..2f946f11940cb91eefabaeaedf26c33f76d874c2 100644 (file)
@@ -305,7 +305,7 @@ public enum PCEPErrors {
     /**
      * Caret for combination of Error-type and Error-value
      */
-    private static final class PCEPErrorIdentifier {
+    private static class PCEPErrorIdentifier {
         private final short type;
         private final short value;
 
index 7a85ecb536ddb1a2c8131cdeee0657f594f32791..81f989a11e36274c2c54e1da170b7cbb4f1cb3b9 100644 (file)
@@ -8,9 +8,7 @@
 package org.opendaylight.protocol.pcep.spi.pojo;
 
 import com.google.common.base.Preconditions;
-
 import io.netty.buffer.ByteBuf;
-
 import org.opendaylight.protocol.concepts.HandlerRegistry;
 import org.opendaylight.protocol.pcep.spi.ObjectParser;
 import org.opendaylight.protocol.pcep.spi.ObjectRegistry;
@@ -29,16 +27,19 @@ import org.opendaylight.yangtools.yang.binding.DataContainer;
 public final class SimpleObjectRegistry implements ObjectRegistry {
     private final HandlerRegistry<DataContainer, ObjectParser, ObjectSerializer> handlers = new HandlerRegistry<>();
 
+    private static final int MAX_OBJECT_TYPE = 15;
+    private static final int MAX_OBJECT_CLASS = 4;
+
     private static int createKey(final int objectClass, final int objectType) {
         Preconditions.checkArgument(objectClass >= 0 && objectClass <= Values.UNSIGNED_BYTE_MAX_VALUE);
-        Preconditions.checkArgument(objectType >= 0 && objectType <= 15);
-        return (objectClass << 4) | objectType;
+        Preconditions.checkArgument(objectType >= 0 && objectType <= MAX_OBJECT_TYPE);
+        return (objectClass << MAX_OBJECT_CLASS) | objectType;
     }
 
     public AutoCloseable registerObjectParser(final int objectClass, final int objectType, final ObjectParser parser) {
-        Preconditions.checkArgument(objectClass >= 0 && objectClass <= Values.UNSIGNED_BYTE_MAX_VALUE, "Illagal object class %s",
+        Preconditions.checkArgument(objectClass >= 0 && objectClass <= Values.UNSIGNED_BYTE_MAX_VALUE, "Illegal object class %s",
                 objectClass);
-        Preconditions.checkArgument(objectType >= 0 && objectType <= 15, "Illegal object type %s", objectType);
+        Preconditions.checkArgument(objectType >= 0 && objectType <= MAX_OBJECT_TYPE, "Illegal object type %s", objectType);
         return this.handlers.registerParser(createKey(objectClass, objectType), parser);
     }
 
@@ -56,7 +57,7 @@ public final class SimpleObjectRegistry implements ObjectRegistry {
             if (!header.isProcessingRule()) {
                 return null;
             }
-            for (int type = 1; type <= 15; type++) {
+            for (int type = 1; type <= MAX_OBJECT_TYPE; type++) {
                 final ObjectParser objParser = this.handlers.getParser(createKey(objectClass, type));
                 if (objParser != null) {
                     return new UnknownObject(PCEPErrors.UNRECOGNIZED_OBJ_TYPE);
index 54d03551a362530e6cca0012233ed9be92971c4e..cb4e8e227647fb31daa0bef1aff32e6e1a964eba 100644 (file)
@@ -66,6 +66,8 @@ public final class Main {
 
     }
 
+    private static final int KA_TO_DEADTIMER_RATIO = 4;
+
     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);
@@ -104,11 +106,11 @@ public final class Main {
             }
             i++;
         }
-        if (deadTimerValue != 0 && deadTimerValue != keepAliveValue * 4) {
+        if (deadTimerValue != 0 && deadTimerValue != keepAliveValue * KA_TO_DEADTIMER_RATIO) {
             LOG.warn("WARNING: The value of DeadTimer should be 4 times the value of KeepAlive.");
         }
         if (deadTimerValue == 0) {
-            deadTimerValue = keepAliveValue * 4;
+            deadTimerValue = keepAliveValue * KA_TO_DEADTIMER_RATIO;
         }
 
         final PCEPSessionProposalFactory spf = new Stateful07SessionProposalFactory(deadTimerValue, keepAliveValue, stateful, active, instant);
index 1531ddc0d1720a572ff249e24c1ffddd03dc6b4d..49c024bf0a383f4e5016c76ebbcb9a7ceced9ce6 100644 (file)
@@ -255,7 +255,9 @@ public abstract class AbstractTopologySessionListener<S, L> implements PCEPSessi
 
     protected final synchronized PCEPRequest removeRequest(final S id) {
         final PCEPRequest ret = this.requests.remove(id);
-        this.listenerState.processRequestStats(ret.getElapsedMillis());
+        if (ret != null) {
+            this.listenerState.processRequestStats(ret.getElapsedMillis());
+        }
         LOG.trace("Removed request {} object {}", id, ret);
         return ret;
     }
@@ -459,7 +461,7 @@ public abstract class AbstractTopologySessionListener<S, L> implements PCEPSessi
     }
 
     @Override
-    public void resetStats() {
+    public synchronized void resetStats() {
         this.listenerState.resetStats(this.session);
     }
 
index f3afdfae8392a313d417838b71aee3a716575ee7..535ba28d066166c0357d737623e32beb732754c7 100644 (file)
@@ -119,52 +119,38 @@ final class ServerSessionManager implements SessionListenerFactory<PCEPSessionLi
         return this.listenerFactory.createTopologySessionListener(this);
     }
 
-    @Override
-    public synchronized ListenableFuture<OperationResult> addLsp(final AddLspArgs input) {
+    private synchronized TopologySessionListener checkSessionPresence(final NodeId nodeId) {
         // Get the listener corresponding to the node
-        final TopologySessionListener l = this.nodes.get(input.getNode());
+        final TopologySessionListener l = this.nodes.get(nodeId);
         if (l == null) {
-            LOG.debug("Session for node {} not found", input.getNode());
-            return OperationResults.UNSENT.future();
+            LOG.debug("Session for node {} not found", nodeId);
+            return null;
         }
+        return l;
+    }
 
-        return l.addLsp(input);
+    @Override
+    public synchronized ListenableFuture<OperationResult> addLsp(final AddLspArgs input) {
+        final TopologySessionListener l = checkSessionPresence(input.getNode());
+        return (l != null) ? l.addLsp(input) : OperationResults.UNSENT.future();
     }
 
     @Override
     public synchronized ListenableFuture<OperationResult> removeLsp(final RemoveLspArgs input) {
-        // Get the listener corresponding to the node
-        final TopologySessionListener l = this.nodes.get(input.getNode());
-        if (l == null) {
-            LOG.debug("Session for node {} not found", input.getNode());
-            return OperationResults.UNSENT.future();
-        }
-
-        return l.removeLsp(input);
+        final TopologySessionListener l = checkSessionPresence(input.getNode());
+        return (l != null) ? l.removeLsp(input) : OperationResults.UNSENT.future();
     }
 
     @Override
     public synchronized ListenableFuture<OperationResult> updateLsp(final UpdateLspArgs input) {
-        // Get the listener corresponding to the node
-        final TopologySessionListener l = this.nodes.get(input.getNode());
-        if (l == null) {
-            LOG.debug("Session for node {} not found", input.getNode());
-            return OperationResults.UNSENT.future();
-        }
-
-        return l.updateLsp(input);
+        final TopologySessionListener l = checkSessionPresence(input.getNode());
+        return (l != null) ? l.updateLsp(input) : OperationResults.UNSENT.future();
     }
 
     @Override
     public synchronized ListenableFuture<OperationResult> ensureLspOperational(final EnsureLspOperationalInput input) {
-        // Get the listener corresponding to the node
-        final TopologySessionListener l = this.nodes.get(input.getNode());
-        if (l == null) {
-            LOG.debug("Session for node {} not found", input.getNode());
-            return OperationResults.UNSENT.future();
-        }
-
-        return l.ensureLspOperational(input);
+        final TopologySessionListener l = checkSessionPresence(input.getNode());
+        return (l != null) ? l.ensureLspOperational(input) : OperationResults.UNSENT.future();
     }
 
     @Override
index b51de23f9edd2fc0822cfd968eae5de566a5fd21..9561d2bfd71c57e47e618c3688e0a127b2180d22 100644 (file)
@@ -30,4 +30,9 @@ public final class Values {
      * Maximum unsigned Byte value in hex (0xFF).
      */
     public static final int BYTE_MAX_VALUE_BYTES = 0xFF;
+
+    /**
+     * In order to get the value in first bit, we need to shift the byte by 7.
+     */
+    public static final int FIRST_BIT_OFFSET = 7;
 }