@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() {
@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);
}
*/
@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);
*/
@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();
/*
- * * 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,
@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;
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;
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);
*/
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;
}
}
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;
@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
*/
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);
@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
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;
}
/**
- * 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
channel.eventLoop().submit(task);
}
+
+ @VisibleForTesting
+ protected void setLastMessageSentAt(final long lastMessageSentAt) {
+ this.lastMessageSentAt = lastMessageSentAt;
+ }
}
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;
@Override
public void sendMessage(final Notification msg) {
- this.lastMessageSentAt = System.nanoTime();
+ this.setLastMessageSentAt(System.nanoTime());
this.client.onMessage(this, msg);
}
}
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;
// 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.
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;
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;
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));
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);
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);
}
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) {
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;
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;
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);
@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");
}
}
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));
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);
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);
}
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));
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);
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());
}
}
*/
private long lastMessageReceivedAt;
- @VisibleForTesting
- protected final Queue<Long> unknownMessagesTimes = new LinkedList<Long>();
+ private final Queue<Long> unknownMessagesTimes = new LinkedList<Long>();
private final PCEPSessionListener listener;
public String getNodeIdentifier() {
return "";
}
+
+ @VisibleForTesting
+ protected final Queue<Long> getUnknownMessagesTimes() {
+ return this.unknownMessagesTimes;
+ }
}
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;
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) {
package org.opendaylight.protocol.pcep.spi;
-public class VendorInformationUtil {
+public final class VendorInformationUtil {
public static final int VENDOR_INFORMATION_TLV_TYPE = 7;
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;
}
- 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;
int deadTimerValue = 0;
boolean stateful = false;
boolean active = false;
- final boolean versioned = false;
boolean instant = false;
int i = 0;
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();
+ }
}
}
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;
*/
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);
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;
private final List<Message> messages = Lists.newArrayList();
- public boolean up = false;
+ private boolean up = false;
private static final Logger LOG = LoggerFactory.getLogger(TestingSessionListener.class);
public List<Message> messages() {
return this.messages;
}
+
+ public boolean isUp () {
+ return this.up;
+ }
}
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());
}
}
};
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<>();
@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);
@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);
@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);
@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) {
final class Stateful07TopologySessionListener extends AbstractTopologySessionListener<SrpIdNumber, PlspId> {
private static final Logger LOG = LoggerFactory.getLogger(Stateful07TopologySessionListener.class);
+
private final AtomicLong requestId = new AtomicLong(1L);
/**
@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());
@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());
@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());
@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) {
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);
@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()) {
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;
final class ProgrammingServiceImplCloseable implements InstructionScheduler, AutoCloseable {
@Override
- public void close() throws Exception {
+ public void close() {
try {
reg.close();
} finally {
* @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];
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.