}
synchronized AutoCloseable registerNlriSerializer(final Class<? extends DataObject> nlriClass, final NlriSerializer serializer){
- final NlriParser prev = this.handlers.get(nlriClass);
+ final NlriSerializer prev = this.serializers.get(nlriClass);
Preconditions.checkState(prev == null, "Serializer already bound to class " + prev);
this.serializers.put(nlriClass, serializer);
}
@Override
- protected void startNegotiation() {
+ protected synchronized void startNegotiation() {
Preconditions.checkState(this.state == State.Idle);
// Check if peer is configured in registry before retrieving preferences
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.BGPSession;
protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
toStringHelper.add("channel", this.channel);
- toStringHelper.add("state", this.state);
+ toStringHelper.add("state", this.getState());
return toStringHelper;
}
import com.google.common.base.Strings;
import com.google.common.collect.Lists;
import com.google.common.io.CharStreams;
-
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.List;
-
import javax.annotation.concurrent.Immutable;
-
import org.apache.commons.codec.DecoderException;
import org.apache.commons.codec.binary.Hex;
import org.opendaylight.protocol.util.ByteArray;
try {
message = Hex.decodeHex(hexMessage.toCharArray());
} catch (final DecoderException e) {
- new IllegalArgumentException("Failed to decode message body", e);
+ throw new IllegalArgumentException("Failed to decode message body", e);
}
messages.add(message);
idx = messageEndIdx;
package org.opendaylight.protocol.pcep.ietf.stateful02;
import com.google.common.collect.Lists;
-
import io.netty.buffer.ByteBuf;
-
import java.util.List;
-
import org.opendaylight.protocol.pcep.impl.message.PCEPRequestMessageParser;
import org.opendaylight.protocol.pcep.spi.ObjectRegistry;
import org.opendaylight.protocol.pcep.spi.PCEPErrors;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Message;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.bandwidth.object.Bandwidth;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.bandwidth.object.BandwidthBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.classtype.object.ClassType;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.exclude.route.object.Xro;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.include.route.object.Iro;
if (rp.isReoptimization()
&& builder.getBandwidth() != null
- && builder.getReportedRoute().getBandwidth().getBandwidth() != new BandwidthBuilder().setBandwidth(
- new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.Bandwidth(new byte[] { 0 })).build()
- && builder.getReportedRoute().getRro() == 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().getRro() == null) {
errors.add(createErrorMsg(PCEPErrors.RRO_MISSING, rp));
return null;
}
import com.google.common.base.Preconditions;
import com.google.common.collect.Lists;
-
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
-
import java.util.List;
-
import org.opendaylight.protocol.pcep.spi.AbstractMessageParser;
import org.opendaylight.protocol.pcep.spi.MessageUtil;
import org.opendaylight.protocol.pcep.spi.ObjectRegistry;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Message;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.bandwidth.object.Bandwidth;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.bandwidth.object.BandwidthBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.classtype.object.ClassType;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.endpoints.object.EndpointsObj;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.exclude.route.object.Xro;
if (msg.getRequests() == null || msg.getRequests().isEmpty()) {
throw new IllegalArgumentException("Requests cannot be null or empty.");
}
- ByteBuf buffer = Unpooled.buffer();
+ final ByteBuf buffer = Unpooled.buffer();
for (final Requests req : msg.getRequests()) {
serializeObject(req.getRp(), buffer);
if (req.getPathKeyExpansion() != null) {
if (rp.isReoptimization()
&& builder.getBandwidth() != null
- && builder.getReportedRoute().getBandwidth().getBandwidth() != new BandwidthBuilder().setBandwidth(
- new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.Bandwidth(new byte[] { 0 })).build()
- && builder.getReportedRoute().getRro() == 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().getRro() == null) {
errors.add(createErrorMsg(PCEPErrors.RRO_MISSING, rp));
return null;
}
import com.google.common.util.concurrent.AsyncFunction;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
-
import java.net.InetAddress;
import java.nio.ByteBuffer;
import java.util.Collections;
-
import javax.annotation.concurrent.GuardedBy;
-
import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
import org.opendaylight.protocol.pcep.PCEPSession;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.initiated._00.rev140113.PcinitiateBuilder;
final ReportedLspBuilder rlb = new ReportedLspBuilder();
rlb.addAugmentation(ReportedLsp1.class, new ReportedLsp1Builder().setLsp(lsp).build());
- org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.pcep.client.attributes.path.computation.client.reported.lsp.PathBuilder pb = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.pcep.client.attributes.path.computation.client.reported.lsp.PathBuilder();
+ final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.pcep.client.attributes.path.computation.client.reported.lsp.PathBuilder pb = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.pcep.client.attributes.path.computation.client.reported.lsp.PathBuilder();
if (r.getPath() != null) {
pb.fieldsFrom(r.getPath());
}
@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, "Mandatory XML tags are missing.");
// Make sure there is no such LSP
final InstanceIdentifier<ReportedLsp> lsp = lspIdentifier(input.getName()).build();
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, "Mandatory XML tags are missing.");
// Make sure the LSP exists, we need it for PLSP-ID
final InstanceIdentifier<ReportedLsp> lsp = lspIdentifier(input.getName()).build();
final ListenableFuture<Optional<ReportedLsp>> f = readOperationalData(lsp);
final ReportedLsp1 ra = rep.get().getAugmentation(ReportedLsp1.class);
Preconditions.checkState(ra != null, "Reported LSP reported null from data-store.");
- Lsp reportedLsp = ra.getLsp();
+ final Lsp reportedLsp = ra.getLsp();
Preconditions.checkState(reportedLsp != null, "Reported LSP does not contain LSP object.");
// Build the request and send it
@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, "Mandatory XML tags are missing.");
// Make sure the LSP exists
final InstanceIdentifier<ReportedLsp> lsp = lspIdentifier(input.getName()).build();
final ListenableFuture<Optional<ReportedLsp>> f = readOperationalData(lsp);
final ReportedLsp1 ra = rep.get().getAugmentation(ReportedLsp1.class);
Preconditions.checkState(ra != null, "Reported LSP reported null from data-store.");
- Lsp reportedLsp = ra.getLsp();
+ final Lsp reportedLsp = ra.getLsp();
Preconditions.checkState(reportedLsp != null, "Reported LSP does not contain LSP object.");
- Arguments2 args = input.getArguments().getAugmentation(Arguments2.class);
+ final Arguments2 args = input.getArguments().getAugmentation(Arguments2.class);
Preconditions.checkArgument(args != null, "Input is missing operational tag.");
Preconditions.checkArgument(input.getArguments().getEro() != null, "Input is missing ERO object.");
@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, "Mandatory XML tags are missing.");
final Boolean op;
final Arguments1 aa = input.getArguments().getAugmentation(Arguments1.class);
if (aa == null) {
LOG.warn("Node {} LSP {} does not contain data", input.getNode(), input.getName());
return OperationResults.UNSENT;
}
- Lsp reportedLsp = ra.getLsp();
+ final Lsp reportedLsp = ra.getLsp();
Preconditions.checkState(reportedLsp != null, "Reported LSP does not contain LSP object.");
if (reportedLsp.isOperational().equals(op)) {
return OperationResults.SUCCESS;
@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, "Mandatory XML tags are missing.");
LOG.trace("AddLspArgs {}", input);
// Make sure there is no such LSP
final InstanceIdentifier<ReportedLsp> lsp = lspIdentifier(input.getName()).build();
// Build the request
final RequestsBuilder rb = new RequestsBuilder();
- Arguments2 args = input.getArguments().getAugmentation(Arguments2.class);
+ final Arguments2 args = input.getArguments().getAugmentation(Arguments2.class);
Preconditions.checkArgument(args != null, "Input is missing operational tag.");
- Lsp inputLsp = args.getLsp();
+ final Lsp inputLsp = args.getLsp();
Preconditions.checkArgument(inputLsp != null, "Reported LSP does not contain LSP object.");
rb.fieldsFrom(input.getArguments());
- TlvsBuilder tlvsBuilder = new TlvsBuilder();
+ final TlvsBuilder tlvsBuilder = new TlvsBuilder();
tlvsBuilder.setSymbolicPathName(
new SymbolicPathNameBuilder().setPathName(new SymbolicPathName(input.getName().getBytes(Charsets.UTF_8))).build());
if (inputLsp.getTlvs() != null) {
@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, "Mandatory XML tags are missing.");
LOG.trace("RemoveLspArgs {}", input);
// Make sure the LSP exists, we need it for PLSP-ID
final InstanceIdentifier<ReportedLsp> lsp = lspIdentifier(input.getName()).build();
// it doesn't matter how many lsps there are in the path list, we only need delegate & plspid that is the same in each path
final Path1 ra = rep.get().getPath().get(0).getAugmentation(Path1.class);
Preconditions.checkState(ra != null, "Reported LSP reported null from data-store.");
- Lsp reportedLsp = ra.getLsp();
+ final Lsp reportedLsp = ra.getLsp();
Preconditions.checkState(reportedLsp != null, "Reported LSP does not contain LSP object.");
// Build the request and send it
@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, "Mandatory XML tags are missing.");
LOG.trace("UpdateLspArgs {}", input);
// Make sure the LSP exists
final InstanceIdentifier<ReportedLsp> lsp = lspIdentifier(input.getName()).build();
// it doesn't matter how many lsps there are in the path list, we only need plspid that is the same in each path
final Path1 ra = rep.get().getPath().get(0).getAugmentation(Path1.class);
Preconditions.checkState(ra != null, "Reported LSP reported null from data-store.");
- Lsp reportedLsp = ra.getLsp();
+ final Lsp reportedLsp = ra.getLsp();
Preconditions.checkState(reportedLsp != null, "Reported LSP does not contain LSP object.");
// Build the PCUpd request and send it
final UpdatesBuilder rb = new UpdatesBuilder();
rb.setSrp(new SrpBuilder().setOperationId(nextRequest()).setProcessingRule(Boolean.TRUE).build());
- Lsp inputLsp = input.getArguments().getAugmentation(Arguments3.class).getLsp();
+ final Lsp inputLsp = input.getArguments().getAugmentation(Arguments3.class).getLsp();
if (inputLsp != null) {
rb.setLsp(new LspBuilder().setPlspId(reportedLsp.getPlspId()).setDelegate((inputLsp.isDelegate() != null) ? inputLsp.isDelegate() : false).setTlvs(inputLsp.getTlvs()).setAdministrative((inputLsp.isAdministrative() != null) ? inputLsp.isAdministrative() : false).build());
} else {
@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, "Mandatory XML tags are missing.");
final OperationalStatus op;
final Arguments1 aa = input.getArguments().getAugmentation(Arguments1.class);
if (aa != null) {
// check if at least one of the paths has the same status as requested
boolean operational = false;
- for (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.pcep.client.attributes.path.computation.client.reported.lsp.Path p : rep.get().getPath()) {
- Path1 p1 = p.getAugmentation(Path1.class);
+ for (final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.pcep.client.attributes.path.computation.client.reported.lsp.Path p : rep.get().getPath()) {
+ final Path1 p1 = p.getAugmentation(Path1.class);
if (p1 == null) {
LOG.warn("Node {} LSP {} does not contain data", input.getNode(), input.getName());
return OperationResults.UNSENT;
}
- Lsp l = p1.getLsp();
+ final Lsp l = p1.getLsp();
if (l.getOperational().equals(op)) {
operational = true;
}
import io.netty.util.concurrent.Promise;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
+import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
-
+ this.receivedMsgs = new ArrayList<>();
doAnswer(new Answer<Object>() {
@Override
public Object answer(final InvocationOnMock invocation) {
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.JdkFutureAdapters;
-
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
-
import org.opendaylight.controller.md.sal.common.api.TransactionStatus;
import org.opendaylight.controller.md.sal.common.api.data.DataChangeEvent;
import org.opendaylight.controller.sal.binding.api.data.DataChangeListener;
if (tpt instanceof Ip) {
for (final IpAddress a : ((Ip) tpt).getIpAddress()) {
- if (addr.equals(a.getIpv6Address())) {
+ if (addr.equals(a)) {
if (sni != null) {
final NodeKey k = InstanceIdentifier.keyOf(sni);
boolean have = false;
LOG.debug("Searching for orphan links/nodes");
final Topology t = (Topology) trans.readOperationalData(this.target);
- NodeId srcNode = l.getSource().getSourceNode();
- NodeId dstNode = l.getDestination().getDestNode();
- TpId srcTp = l.getSource().getSourceTp();
- TpId dstTp = l.getDestination().getDestTp();
+ final NodeId srcNode = l.getSource().getSourceNode();
+ final NodeId dstNode = l.getDestination().getDestNode();
+ final TpId srcTp = l.getSource().getSourceTp();
+ final TpId dstTp = l.getDestination().getDestTp();
boolean orphSrcNode = true, orphDstNode = true, orphDstTp = true, orphSrcTp = true;
for (final Link lw : t.getLink()) {
return id;
}
- InstructionStatus getStatus() {
- return status;
+ synchronized InstructionStatus getStatus() {
+ return this.status;
}
synchronized void setStatus(final InstructionStatus status, final Details details) {
}
// The instruction is in a terminal state, we need to just unlink
- // it from its dependencies and dependants
+ // it from its dependencies and dependents
i.clean();
- insns.remove(i);
+ this.insns.remove(id);
LOG.debug("Instruction {} cleaned successfully", id);
}
import com.google.common.base.Preconditions;
import com.google.common.primitives.UnsignedInteger;
-
import io.netty.buffer.ByteBuf;
-
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.Arrays;
import java.util.BitSet;
-
import org.apache.commons.codec.binary.Hex;
/**
* @param length length of the returned byte array
* @return byte array
*/
- public static byte[] readBytes(final ByteBuf buffer, int length) {
- Preconditions.checkState(buffer != null && buffer.readableBytes() >= length,
- "Buffer cannot be read for %s bytes. Contains only %s bytes.", length, buffer.readableBytes());
- byte[] result = new byte[length];
+ public static byte[] readBytes(final ByteBuf buffer, final int length) {
+ Preconditions.checkArgument(buffer != null && buffer.readableBytes() >= length,
+ "Buffer cannot be read for %s bytes.", length);
+ final byte[] result = new byte[length];
buffer.readBytes(result);
return result;
}
* @param length length of the returned byte array
* @return byte array
*/
- public static byte[] getBytes(final ByteBuf buffer, int length) {
- Preconditions.checkState(buffer != null && buffer.readableBytes() >= length,
- "Buffer cannot be read for %s bytes. Contains only %s bytes.", length, buffer.readableBytes());
- byte[] result = new byte[length];
+ public static byte[] getBytes(final ByteBuf buffer, final int length) {
+ Preconditions.checkArgument(buffer != null && buffer.readableBytes() >= length,
+ "Buffer cannot be read for %s bytes.", length);
+ final byte[] result = new byte[length];
buffer.getBytes(buffer.readerIndex(), result);
return result;
}
import com.google.common.base.Preconditions;
import com.google.common.collect.Lists;
import com.google.common.io.CharStreams;
-
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.List;
-
import org.apache.commons.codec.DecoderException;
import org.apache.commons.codec.binary.Hex;
import org.slf4j.Logger;
// next chars are final length, ending with '.'
final int lengthIdx = idx + LENGTH.length();
final int messageIdx = content.indexOf('.', lengthIdx);
-
final int length = Integer.valueOf(content.substring(lengthIdx, messageIdx));
- final int messageEndIdx = idx + length * 2;
+ final int messageEndIdx = messageIdx + (length * 2) + 1; // dot
// Assert that message is longer than minimum 4(header.length == 4)
// If length in PCEP message would be 0, loop would never end
Preconditions.checkArgument(length >= MINIMAL_LENGTH, "Invalid message at index " + idx + ", length atribute is lower than "
+ MINIMAL_LENGTH);
- final String hexMessage = content.substring(idx, messageEndIdx);
+ final String hexMessage = content.substring(messageIdx + 1, messageEndIdx); // dot
byte[] message = null;
try {
message = Hex.decodeHex(hexMessage.toCharArray());
} catch (final DecoderException e) {
- new IllegalArgumentException("Failed to decode message", e);
+ throw new IllegalArgumentException("Failed to decode message", e);
}
messages.add(message);
idx = messageEndIdx;