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;
}
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);
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;
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);
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");
}
}
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;
}
@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;
out.add(parse(in, errors));
} catch (final PCEPDeserializerException e) {
LOG.debug("Failed to decode protocol message", e);
- this.exceptionCaught(ctx, e);
}
in.discardReadBytes();
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();
}
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;
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());
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;
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());
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);
}
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 {
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;
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());
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;
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;
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;
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;
}
});
}
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;
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);
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;
}
}
}
/**
* 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;
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;
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);
}
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);
}
+ 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);
}
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);
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;
}
}
@Override
- public void resetStats() {
+ public synchronized void resetStats() {
this.listenerState.resetStats(this.session);
}
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
* 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;
}