static final NodeIdentifier FLOWSPEC_NID = new NodeIdentifier(Flowspec.QNAME);
@VisibleForTesting
static final NodeIdentifier FLOWSPEC_TYPE_NID = new NodeIdentifier(FlowspecType.QNAME);
- public static final NodeIdentifier DEST_PREFIX_NID = new NodeIdentifier(QName.create(DestinationPrefixCase.QNAME, "destination-prefix").intern());
- public static final NodeIdentifier SOURCE_PREFIX_NID = new NodeIdentifier(QName.create(SourcePrefixCase.QNAME, "source-prefix").intern());
+ public static final NodeIdentifier DEST_PREFIX_NID
+ = new NodeIdentifier(QName.create(DestinationPrefixCase.QNAME, "destination-prefix").intern());
+ public static final NodeIdentifier SOURCE_PREFIX_NID
+ = new NodeIdentifier(QName.create(SourcePrefixCase.QNAME, "source-prefix").intern());
@VisibleForTesting
static final NodeIdentifier PORTS_NID = new NodeIdentifier(Ports.QNAME);
@VisibleForTesting
@VisibleForTesting
static final NodeIdentifier FRAGMENT_NID = new NodeIdentifier(Fragments.QNAME);
@VisibleForTesting
- public static final NodeIdentifier OP_NID = new NodeIdentifier(QName.create(Flowspec.QNAME.getNamespace(), Flowspec.QNAME.getRevision(), "op"));
+ public static final NodeIdentifier OP_NID
+ = new NodeIdentifier(QName.create(Flowspec.QNAME.getModule(), "op"));
@VisibleForTesting
- public static final NodeIdentifier VALUE_NID = new NodeIdentifier(QName.create(Flowspec.QNAME.getNamespace(), Flowspec.QNAME.getRevision(), "value"));
+ public static final NodeIdentifier VALUE_NID
+ = new NodeIdentifier(QName.create(Flowspec.QNAME.getModule(), "value"));
- protected SimpleFlowspecTypeRegistry flowspecTypeRegistry;
+ protected final SimpleFlowspecTypeRegistry flowspecTypeRegistry;
/**
* Add this constant to length value to achieve all ones in the leftmost nibble.
* @param pathId associated path id with given NLRI
* @return created destination type
*/
- public abstract DestinationType createWithdrawnDestinationType(@Nonnull final Object[] nlriFields, @Nullable final PathId pathId);
+ public abstract DestinationType createWithdrawnDestinationType(@Nonnull Object[] nlriFields,
+ @Nullable PathId pathId);
/**
* Create advertized destination type
* @param pathId associated path id with given NLRI
* @return created destination type
*/
- public abstract DestinationType createAdvertizedRoutesDestinationType(@Nonnull final Object[] nlriFields, @Nullable final PathId pathId);
+ public abstract DestinationType createAdvertizedRoutesDestinationType(@Nonnull Object[] nlriFields, @Nullable PathId pathId);
@Override
public final void serializeAttribute(final DataObject attribute, final ByteBuf byteAggregator) {
- Preconditions.checkArgument(attribute instanceof Attributes, "Attribute parameter is not a PathAttribute object.");
+ Preconditions.checkArgument(attribute instanceof Attributes,
+ "Attribute parameter is not a PathAttribute object.");
final Attributes pathAttributes = (Attributes) attribute;
final Attributes1 pathAttributes1 = pathAttributes.getAugmentation(Attributes1.class);
final Attributes2 pathAttributes2 = pathAttributes.getAugmentation(Attributes2.class);
* @param pathId
* @param buffer where flowspec NLRI will be serialized
*/
- protected final void serializeNlri(@Nonnull final Object[] nlriFields, @Nullable final PathId pathId, @Nonnull final ByteBuf buffer) {
+ protected final void serializeNlri(@Nonnull final Object[] nlriFields, @Nullable final PathId pathId,
+ @Nonnull final ByteBuf buffer) {
final ByteBuf nlriByteBuf = Unpooled.buffer();
PathIdUtil.writePathId(pathId, buffer);
serializeNlri(nlriFields, nlriByteBuf);
- Preconditions.checkState(nlriByteBuf.readableBytes() <= MAX_NLRI_LENGTH, "Maximum length of Flowspec NLRI reached.");
+ Preconditions.checkState(nlriByteBuf.readableBytes() <= MAX_NLRI_LENGTH,
+ "Maximum length of Flowspec NLRI reached.");
if (nlriByteBuf.readableBytes() <= MAX_NLRI_LENGTH_ONE_BYTE) {
buffer.writeByte(nlriByteBuf.readableBytes());
} else {
private void processFlowspecType(final ChoiceNode fsType, final FlowspecBuilder fsBuilder) {
if (fsType.getChild(PORTS_NID).isPresent()) {
- fsBuilder.setFlowspecType(new PortCaseBuilder().setPorts(createPorts((UnkeyedListNode) fsType.getChild(PORTS_NID).get())).build());
+ fsBuilder.setFlowspecType(new PortCaseBuilder()
+ .setPorts(createPorts((UnkeyedListNode) fsType.getChild(PORTS_NID).get())).build());
} else if (fsType.getChild(DEST_PORT_NID).isPresent()) {
- fsBuilder.setFlowspecType(new DestinationPortCaseBuilder().setDestinationPorts(createDestinationPorts((UnkeyedListNode) fsType.getChild(DEST_PORT_NID).get())).build());
+ fsBuilder.setFlowspecType(new DestinationPortCaseBuilder()
+ .setDestinationPorts(createDestinationPorts((UnkeyedListNode) fsType.getChild(DEST_PORT_NID).get()))
+ .build());
} else if (fsType.getChild(SOURCE_PORT_NID).isPresent()) {
- fsBuilder.setFlowspecType(new SourcePortCaseBuilder().setSourcePorts(createSourcePorts((UnkeyedListNode) fsType.getChild(SOURCE_PORT_NID).get())).build());
+ fsBuilder.setFlowspecType(new SourcePortCaseBuilder()
+ .setSourcePorts(createSourcePorts((UnkeyedListNode) fsType.getChild(SOURCE_PORT_NID).get()))
+ .build());
} else if (fsType.getChild(ICMP_TYPE_NID).isPresent()) {
- fsBuilder.setFlowspecType(new IcmpTypeCaseBuilder().setTypes(createTypes((UnkeyedListNode) fsType.getChild(ICMP_TYPE_NID).get())).build());
+ fsBuilder.setFlowspecType(new IcmpTypeCaseBuilder()
+ .setTypes(createTypes((UnkeyedListNode) fsType.getChild(ICMP_TYPE_NID).get())).build());
} else if (fsType.getChild(ICMP_CODE_NID).isPresent()) {
- fsBuilder.setFlowspecType(new IcmpCodeCaseBuilder().setCodes(createCodes((UnkeyedListNode) fsType.getChild(ICMP_CODE_NID).get())).build());
+ fsBuilder.setFlowspecType(new IcmpCodeCaseBuilder()
+ .setCodes(createCodes((UnkeyedListNode) fsType.getChild(ICMP_CODE_NID).get())).build());
} else if (fsType.getChild(TCP_FLAGS_NID).isPresent()) {
- fsBuilder.setFlowspecType(new TcpFlagsCaseBuilder().setTcpFlags(createTcpFlags((UnkeyedListNode) fsType.getChild(TCP_FLAGS_NID).get())).build());
+ fsBuilder.setFlowspecType(new TcpFlagsCaseBuilder()
+ .setTcpFlags(createTcpFlags((UnkeyedListNode) fsType.getChild(TCP_FLAGS_NID).get())).build());
} else if (fsType.getChild(PACKET_LENGTHS_NID).isPresent()) {
- fsBuilder.setFlowspecType(new PacketLengthCaseBuilder().setPacketLengths(createPacketLengths((UnkeyedListNode) fsType.getChild(PACKET_LENGTHS_NID).get())).build());
+ fsBuilder.setFlowspecType(new PacketLengthCaseBuilder()
+ .setPacketLengths(createPacketLengths((UnkeyedListNode) fsType.getChild(PACKET_LENGTHS_NID).get()))
+ .build());
} else if (fsType.getChild(DSCP_NID).isPresent()) {
- fsBuilder.setFlowspecType(new DscpCaseBuilder().setDscps(createDscpsLengths((UnkeyedListNode) fsType.getChild(DSCP_NID).get())).build());
+ fsBuilder.setFlowspecType(new DscpCaseBuilder()
+ .setDscps(createDscpsLengths((UnkeyedListNode) fsType.getChild(DSCP_NID).get())).build());
} else if (fsType.getChild(FRAGMENT_NID).isPresent()) {
- fsBuilder.setFlowspecType(new FragmentCaseBuilder().setFragments(createFragments((UnkeyedListNode) fsType.getChild(FRAGMENT_NID).get())).build());
+ fsBuilder.setFlowspecType(new FragmentCaseBuilder()
+ .setFragments(createFragments((UnkeyedListNode) fsType.getChild(FRAGMENT_NID).get())).build());
} else {
extractSpecificFlowspec(fsType, fsBuilder);
}
for (final UnkeyedListEntryNode node : portsData.getValue()) {
final PortsBuilder portsBuilder = new PortsBuilder();
final Optional<DataContainerChild<? extends PathArgument, ?>> opValue = node.getChild(OP_NID);
- if (opValue.isPresent()) {
- portsBuilder.setOp(NumericTwoByteOperandParser.INSTANCE.create((Set<String>) opValue.get().getValue()));
- }
+ opValue.ifPresent(dataContainerChild -> portsBuilder
+ .setOp(NumericTwoByteOperandParser.INSTANCE.create((Set<String>) dataContainerChild.getValue())));
final Optional<DataContainerChild<? extends PathArgument, ?>> valueNode = node.getChild(VALUE_NID);
- if (valueNode.isPresent()) {
- portsBuilder.setValue((Integer) valueNode.get().getValue());
- }
+ valueNode.ifPresent(dataContainerChild -> portsBuilder.setValue((Integer) dataContainerChild.getValue()));
ports.add(portsBuilder.build());
}
for (final UnkeyedListEntryNode node : destinationPortsData.getValue()) {
final DestinationPortsBuilder destPortsBuilder = new DestinationPortsBuilder();
final Optional<DataContainerChild<? extends PathArgument, ?>> opValue = node.getChild(OP_NID);
- if (opValue.isPresent()) {
- destPortsBuilder.setOp(NumericTwoByteOperandParser.INSTANCE.create((Set<String>) opValue.get().getValue()));
- }
+ opValue.ifPresent(dataContainerChild -> destPortsBuilder.setOp(NumericTwoByteOperandParser
+ .INSTANCE.create((Set<String>) dataContainerChild.getValue())));
final Optional<DataContainerChild<? extends PathArgument, ?>> valueNode = node.getChild(VALUE_NID);
- if (valueNode.isPresent()) {
- destPortsBuilder.setValue((Integer) valueNode.get().getValue());
- }
+ valueNode.ifPresent(dataContainerChild
+ -> destPortsBuilder.setValue((Integer) dataContainerChild.getValue()));
destinationPorts.add(destPortsBuilder.build());
}
for (final UnkeyedListEntryNode node : sourcePortsData.getValue()) {
final SourcePortsBuilder sourcePortsBuilder = new SourcePortsBuilder();
final Optional<DataContainerChild<? extends PathArgument, ?>> opValue = node.getChild(OP_NID);
- if (opValue.isPresent()) {
- sourcePortsBuilder.setOp(NumericTwoByteOperandParser.INSTANCE.create((Set<String>) opValue.get().getValue()));
- }
+ opValue.ifPresent(dataContainerChild -> sourcePortsBuilder.setOp(NumericTwoByteOperandParser
+ .INSTANCE.create((Set<String>) dataContainerChild.getValue())));
final Optional<DataContainerChild<? extends PathArgument, ?>> valueNode = node.getChild(VALUE_NID);
- if (valueNode.isPresent()) {
- sourcePortsBuilder.setValue((Integer) valueNode.get().getValue());
- }
+ valueNode.ifPresent(dataContainerChild
+ -> sourcePortsBuilder.setValue((Integer) dataContainerChild.getValue()));
sourcePorts.add(sourcePortsBuilder.build());
}
for (final UnkeyedListEntryNode node : typesData.getValue()) {
final TypesBuilder typesBuilder = new TypesBuilder();
final Optional<DataContainerChild<? extends PathArgument, ?>> opValue = node.getChild(OP_NID);
- if (opValue.isPresent()) {
- typesBuilder.setOp(NumericOneByteOperandParser.INSTANCE.create((Set<String>) opValue.get().getValue()));
- }
+ opValue.ifPresent(dataContainerChild -> typesBuilder.setOp(NumericOneByteOperandParser
+ .INSTANCE.create((Set<String>) dataContainerChild.getValue())));
final Optional<DataContainerChild<? extends PathArgument, ?>> valueNode = node.getChild(VALUE_NID);
- if (valueNode.isPresent()) {
- typesBuilder.setValue((Short) valueNode.get().getValue());
- }
+ valueNode.ifPresent(dataContainerChild -> typesBuilder.setValue((Short) dataContainerChild.getValue()));
types.add(typesBuilder.build());
}
for (final UnkeyedListEntryNode node : codesData.getValue()) {
final CodesBuilder codesBuilder = new CodesBuilder();
final Optional<DataContainerChild<? extends PathArgument, ?>> opValue = node.getChild(OP_NID);
- if (opValue.isPresent()) {
- codesBuilder.setOp(NumericOneByteOperandParser.INSTANCE.create((Set<String>) opValue.get().getValue()));
- }
+ opValue.ifPresent(dataContainerChild -> codesBuilder.setOp(NumericOneByteOperandParser
+ .INSTANCE.create((Set<String>) dataContainerChild.getValue())));
final Optional<DataContainerChild<? extends PathArgument, ?>> valueNode = node.getChild(VALUE_NID);
- if (valueNode.isPresent()) {
- codesBuilder.setValue((Short) valueNode.get().getValue());
- }
+ valueNode.ifPresent(dataContainerChild -> codesBuilder.setValue((Short) dataContainerChild.getValue()));
codes.add(codesBuilder.build());
}
for (final UnkeyedListEntryNode node : tcpFlagsData.getValue()) {
final TcpFlagsBuilder tcpFlagsBuilder = new TcpFlagsBuilder();
final Optional<DataContainerChild<? extends PathArgument, ?>> opValue = node.getChild(OP_NID);
- if (opValue.isPresent()) {
- tcpFlagsBuilder.setOp(BitmaskOperandParser.INSTANCE.create((Set<String>) opValue.get().getValue()));
- }
+ opValue.ifPresent(dataContainerChild -> tcpFlagsBuilder
+ .setOp(BitmaskOperandParser.INSTANCE.create((Set<String>) dataContainerChild.getValue())));
final Optional<DataContainerChild<? extends PathArgument, ?>> valueNode = node.getChild(VALUE_NID);
- if (valueNode.isPresent()) {
- tcpFlagsBuilder.setValue((Integer) valueNode.get().getValue());
- }
+ valueNode.ifPresent(dataContainerChild
+ -> tcpFlagsBuilder.setValue((Integer) dataContainerChild.getValue()));
tcpFlags.add(tcpFlagsBuilder.build());
}
for (final UnkeyedListEntryNode node : packetLengthsData.getValue()) {
final PacketLengthsBuilder packetLengthsBuilder = new PacketLengthsBuilder();
final Optional<DataContainerChild<? extends PathArgument, ?>> opValue = node.getChild(OP_NID);
- if (opValue.isPresent()) {
- packetLengthsBuilder.setOp(NumericTwoByteOperandParser.INSTANCE.create((Set<String>) opValue.get().getValue()));
- }
+ opValue.ifPresent(dataContainerChild -> packetLengthsBuilder.setOp(NumericTwoByteOperandParser
+ .INSTANCE.create((Set<String>) dataContainerChild.getValue())));
final Optional<DataContainerChild<? extends PathArgument, ?>> valueNode = node.getChild(VALUE_NID);
- if (valueNode.isPresent()) {
- packetLengthsBuilder.setValue((Integer) valueNode.get().getValue());
- }
+ valueNode.ifPresent(dataContainerChild
+ -> packetLengthsBuilder.setValue((Integer) dataContainerChild.getValue()));
packetLengths.add(packetLengthsBuilder.build());
}
for (final UnkeyedListEntryNode node : dscpLengthsData.getValue()) {
final DscpsBuilder dscpsLengthsBuilder = new DscpsBuilder();
final Optional<DataContainerChild<? extends PathArgument, ?>> opValue = node.getChild(OP_NID);
- if (opValue.isPresent()) {
- dscpsLengthsBuilder.setOp(NumericOneByteOperandParser.INSTANCE.create((Set<String>) opValue.get().getValue()));
- }
+ opValue.ifPresent(dataContainerChild -> dscpsLengthsBuilder.setOp(NumericOneByteOperandParser
+ .INSTANCE.create((Set<String>) dataContainerChild.getValue())));
final Optional<DataContainerChild<? extends PathArgument, ?>> valueNode = node.getChild(VALUE_NID);
- if (valueNode.isPresent()) {
- dscpsLengthsBuilder.setValue(new Dscp((Short) valueNode.get().getValue()));
- }
+ valueNode.ifPresent(dataContainerChild
+ -> dscpsLengthsBuilder.setValue(new Dscp((Short) dataContainerChild.getValue())));
dscpsLengths.add(dscpsLengthsBuilder.build());
}
for (final UnkeyedListEntryNode node : fragmentsData.getValue()) {
final FragmentsBuilder fragmentsBuilder = new FragmentsBuilder();
final Optional<DataContainerChild<? extends PathArgument, ?>> opValue = node.getChild(OP_NID);
- if (opValue.isPresent()) {
- fragmentsBuilder.setOp(BitmaskOperandParser.INSTANCE.create((Set<String>) opValue.get().getValue()));
- }
+ opValue.ifPresent(dataContainerChild -> fragmentsBuilder.setOp(BitmaskOperandParser
+ .INSTANCE.create((Set<String>) dataContainerChild.getValue())));
final Optional<DataContainerChild<? extends PathArgument, ?>> valueNode = node.getChild(VALUE_NID);
- if (valueNode.isPresent()) {
- fragmentsBuilder.setValue(createFragment((Set<String>) valueNode.get().getValue()));
- }
+ valueNode.ifPresent(dataContainerChild
+ -> fragmentsBuilder.setValue(createFragment((Set<String>) dataContainerChild.getValue())));
fragments.add(fragmentsBuilder.build());
}
}
private static Fragment createFragment(final Set<String> data) {
- return new Fragment(data.contains(DO_NOT_VALUE), data.contains(FIRST_VALUE), data.contains(IS_A_VALUE), data.contains(LAST_VALUE));
+ return new Fragment(data.contains(DO_NOT_VALUE), data.contains(FIRST_VALUE), data.contains(IS_A_VALUE),
+ data.contains(LAST_VALUE));
}
protected final String stringNlri(final List<Flowspec> flows) {
buffer.append(NumericTwoByteOperandParser.INSTANCE.toString(((PortCase) value).getPorts()));
} else if (value instanceof DestinationPortCase) {
buffer.append("where destination port ");
- buffer.append(NumericTwoByteOperandParser.INSTANCE.toString(((DestinationPortCase) value).getDestinationPorts()));
+ buffer.append(NumericTwoByteOperandParser
+ .INSTANCE.toString(((DestinationPortCase) value).getDestinationPorts()));
} else if (value instanceof SourcePortCase) {
buffer.append("where source port ");
buffer.append(NumericTwoByteOperandParser.INSTANCE.toString(((SourcePortCase) value).getSourcePorts()));
if (length >= MAX_NLRI_LENGTH_ONE_BYTE) {
length = (length << Byte.SIZE | nlri.readUnsignedByte()) & MAX_NLRI_LENGTH;
}
- Preconditions.checkState(length > 0 && length <= nlri.readableBytes(), "Invalid flowspec NLRI length %s", length);
+ Preconditions.checkState(length > 0 && length <= nlri.readableBytes(),
+ "Invalid flowspec NLRI length %s", length);
return length;
}
while (nlri.isReadable()) {
int nlriLength = readNlriLength(nlri);
- Preconditions.checkState(nlriLength > 0 && nlriLength <= nlri.readableBytes(), "Invalid flowspec NLRI length %s", nlriLength);
+ Preconditions.checkState(nlriLength > 0 && nlriLength <= nlri.readableBytes(),
+ "Invalid flowspec NLRI length %s", nlriLength);
LOG.trace("Flowspec NLRI length is {}", nlriLength);
while (nlriLength > 0) {
final int flowspecTypeLength = readableLength - nlri.readableBytes();
nlriLength -= flowspecTypeLength;
}
- Preconditions.checkState(nlriLength == 0, "Remain NLRI length should be 0 instead of %s", nlriLength);
+ Preconditions.checkState(nlriLength == 0,
+ "Remain NLRI length should be 0 instead of %s", nlriLength);
}
return fss;
}
@Override
- public final void parseNlri(@Nonnull final ByteBuf nlri, @Nonnull final MpReachNlriBuilder builder, @Nullable final PeerSpecificParserConstraint constraint)
+ public final void parseNlri(@Nonnull final ByteBuf nlri, @Nonnull final MpReachNlriBuilder builder,
+ @Nullable final PeerSpecificParserConstraint constraint)
throws BGPParsingException {
if (!nlri.isReadable()) {
return;
public static void extractFlowspec(final ChoiceNode fsType, final FlowspecBuilder fsBuilder) {
if (fsType.getChild(AbstractFlowspecNlriParser.DEST_PREFIX_NID).isPresent()) {
- fsBuilder.setFlowspecType(
- new DestinationPrefixCaseBuilder()
- .setDestinationPrefix(
- new Ipv4Prefix((String) fsType.getChild(AbstractFlowspecNlriParser.DEST_PREFIX_NID).get().getValue())
- ).build()
- );
+ fsBuilder.setFlowspecType(new DestinationPrefixCaseBuilder().setDestinationPrefix(
+ new Ipv4Prefix((String) fsType.getChild(AbstractFlowspecNlriParser.DEST_PREFIX_NID).get()
+ .getValue())).build());
} else if (fsType.getChild(AbstractFlowspecNlriParser.SOURCE_PREFIX_NID).isPresent()) {
- fsBuilder.setFlowspecType(
- new SourcePrefixCaseBuilder()
- .setSourcePrefix(
- new Ipv4Prefix((String) fsType.getChild(AbstractFlowspecNlriParser.SOURCE_PREFIX_NID).get().getValue())
- ).build()
- );
+ fsBuilder.setFlowspecType(new SourcePrefixCaseBuilder().setSourcePrefix(new Ipv4Prefix((String) fsType
+ .getChild(AbstractFlowspecNlriParser.SOURCE_PREFIX_NID).get().getValue())).build());
} else if (fsType.getChild(PROTOCOL_IP_NID).isPresent()) {
- fsBuilder.setFlowspecType(new ProtocolIpCaseBuilder().setProtocolIps(createProtocolsIps((UnkeyedListNode) fsType.getChild(PROTOCOL_IP_NID).get())).build());
+ fsBuilder.setFlowspecType(new ProtocolIpCaseBuilder()
+ .setProtocolIps(createProtocolsIps((UnkeyedListNode) fsType.getChild(PROTOCOL_IP_NID).get()))
+ .build());
}
}
for (final UnkeyedListEntryNode node : protocolIpsData.getValue()) {
final ProtocolIpsBuilder ipsBuilder = new ProtocolIpsBuilder();
- final Optional<DataContainerChild<? extends PathArgument, ?>> opValue = node.getChild(AbstractFlowspecNlriParser.OP_NID);
- if (opValue.isPresent()) {
- ipsBuilder.setOp(NumericOneByteOperandParser.INSTANCE.create((Set<String>) opValue.get().getValue()));
- }
- final Optional<DataContainerChild<? extends PathArgument, ?>> valueNode = node.getChild(AbstractFlowspecNlriParser.VALUE_NID);
- if (valueNode.isPresent()) {
- ipsBuilder.setValue((Short) valueNode.get().getValue());
- }
+ final Optional<DataContainerChild<? extends PathArgument, ?>> opValue
+ = node.getChild(AbstractFlowspecNlriParser.OP_NID);
+ opValue.ifPresent(dataContainerChild -> ipsBuilder.setOp(NumericOneByteOperandParser
+ .INSTANCE.create((Set<String>) dataContainerChild.getValue())));
+ final Optional<DataContainerChild<? extends PathArgument, ?>> valueNode
+ = node.getChild(AbstractFlowspecNlriParser.VALUE_NID);
+ valueNode.ifPresent(dataContainerChild -> ipsBuilder.setValue((Short) dataContainerChild.getValue()));
protocolIps.add(ipsBuilder.build());
}
public static void extractFlowspec(final ChoiceNode fsType, final FlowspecBuilder fsBuilder) {
if (fsType.getChild(AbstractFlowspecNlriParser.DEST_PREFIX_NID).isPresent()) {
- fsBuilder.setFlowspecType(
- new DestinationIpv6PrefixCaseBuilder()
- .setDestinationPrefix(new Ipv6Prefix((String) fsType.getChild(AbstractFlowspecNlriParser.DEST_PREFIX_NID).get().getValue()))
- .build()
- );
+ fsBuilder.setFlowspecType(new DestinationIpv6PrefixCaseBuilder()
+ .setDestinationPrefix(new Ipv6Prefix((String) fsType
+ .getChild(AbstractFlowspecNlriParser.DEST_PREFIX_NID).get().getValue())).build());
} else if (fsType.getChild(AbstractFlowspecNlriParser.SOURCE_PREFIX_NID).isPresent()) {
- fsBuilder.setFlowspecType(
- new SourceIpv6PrefixCaseBuilder()
- .setSourcePrefix(new Ipv6Prefix((String) fsType.getChild(AbstractFlowspecNlriParser.SOURCE_PREFIX_NID).get().getValue()))
- .build()
- );
+ fsBuilder.setFlowspecType(new SourceIpv6PrefixCaseBuilder().setSourcePrefix(new Ipv6Prefix((String) fsType
+ .getChild(AbstractFlowspecNlriParser.SOURCE_PREFIX_NID).get().getValue())).build());
} else if (fsType.getChild(NEXT_HEADER_NID).isPresent()) {
- fsBuilder.setFlowspecType(new NextHeaderCaseBuilder().setNextHeaders(createNextHeaders((UnkeyedListNode) fsType.getChild(NEXT_HEADER_NID).get())).build());
+ fsBuilder.setFlowspecType(new NextHeaderCaseBuilder()
+ .setNextHeaders(createNextHeaders((UnkeyedListNode) fsType.getChild(NEXT_HEADER_NID).get()))
+ .build());
} else if (fsType.getChild(FLOW_LABEL_NID).isPresent()) {
- fsBuilder.setFlowspecType(new FlowLabelCaseBuilder().setFlowLabel(createFlowLabels((UnkeyedListNode) fsType.getChild(FLOW_LABEL_NID).get())).build());
+ fsBuilder.setFlowspecType(new FlowLabelCaseBuilder()
+ .setFlowLabel(createFlowLabels((UnkeyedListNode) fsType.getChild(FLOW_LABEL_NID).get())).build());
}
}
for (final UnkeyedListEntryNode node : nextHeadersData.getValue()) {
final NextHeadersBuilder nextHeadersBuilder = new NextHeadersBuilder();
- final Optional<DataContainerChild<? extends PathArgument, ?>> opValue = node.getChild(AbstractFlowspecNlriParser.OP_NID);
- if (opValue.isPresent()) {
- nextHeadersBuilder.setOp(NumericOneByteOperandParser.INSTANCE.create((Set<String>) opValue.get().getValue()));
- }
- final Optional<DataContainerChild<? extends PathArgument, ?>> valueNode = node.getChild(AbstractFlowspecNlriParser.VALUE_NID);
- if (valueNode.isPresent()) {
- nextHeadersBuilder.setValue((Short) valueNode.get().getValue());
- }
+ final Optional<DataContainerChild<? extends PathArgument, ?>> opValue
+ = node.getChild(AbstractFlowspecNlriParser.OP_NID);
+ opValue.ifPresent(dataContainerChild -> nextHeadersBuilder.setOp(NumericOneByteOperandParser
+ .INSTANCE.create((Set<String>) dataContainerChild.getValue())));
+ final Optional<DataContainerChild<? extends PathArgument, ?>> valueNode
+ = node.getChild(AbstractFlowspecNlriParser.VALUE_NID);
+ valueNode.ifPresent(dataContainerChild
+ -> nextHeadersBuilder.setValue((Short) dataContainerChild.getValue()));
nextHeaders.add(nextHeadersBuilder.build());
}
for (final UnkeyedListEntryNode node : flowLabelsData.getValue()) {
final FlowLabelBuilder flowLabelsBuilder = new FlowLabelBuilder();
- final Optional<DataContainerChild<? extends PathArgument, ?>> opValue = node.getChild(AbstractFlowspecNlriParser.OP_NID);
- if (opValue.isPresent()) {
- flowLabelsBuilder.setOp(NumericOneByteOperandParser.INSTANCE.create((Set<String>) opValue.get().getValue()));
- }
- final Optional<DataContainerChild<? extends PathArgument, ?>> valueNode = node.getChild(AbstractFlowspecNlriParser.VALUE_NID);
- if (valueNode.isPresent()) {
- flowLabelsBuilder.setValue((Long) valueNode.get().getValue());
- }
+ final Optional<DataContainerChild<? extends PathArgument, ?>> opValue
+ = node.getChild(AbstractFlowspecNlriParser.OP_NID);
+ opValue.ifPresent(dataContainerChild -> flowLabelsBuilder.setOp(NumericOneByteOperandParser
+ .INSTANCE.create((Set<String>) dataContainerChild.getValue())));
+ final Optional<DataContainerChild<? extends PathArgument, ?>> valueNode
+ = node.getChild(AbstractFlowspecNlriParser.VALUE_NID);
+ valueNode.ifPresent(dataContainerChild
+ -> flowLabelsBuilder.setValue((Long) dataContainerChild.getValue()));
flowLabels.add(flowLabelsBuilder.build());
}
package org.opendaylight.protocol.bgp.inet.codec;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
import com.google.common.collect.Lists;
import io.netty.buffer.ByteBuf;
.getDestinationType());
assertEquals(this.ip4caseWD.hashCode(), b.getWithdrawnRoutes().getDestinationType().hashCode());
- assertFalse(this.ip4caseWDWrong.hashCode() == b.getWithdrawnRoutes().getDestinationType().hashCode());
+ assertNotEquals(this.ip4caseWDWrong.hashCode(), b.getWithdrawnRoutes().getDestinationType().hashCode());
- assertTrue(this.ip4caseWD.toString().equals(b.getWithdrawnRoutes().getDestinationType().toString()));
- assertFalse(this.ip4caseWDWrong.toString().equals(b.getWithdrawnRoutes().getDestinationType().toString()));
+ assertEquals(this.ip4caseWD.toString(), b.getWithdrawnRoutes().getDestinationType().toString());
+ assertNotEquals(this.ip4caseWDWrong.toString(), b.getWithdrawnRoutes().getDestinationType().toString());
}
@Test
.getDestinationType());
assertEquals(this.ip4caseAD.hashCode(), b.getAdvertizedRoutes().getDestinationType().hashCode());
- assertFalse(this.ip4caseADWrong.hashCode() == b.getAdvertizedRoutes().getDestinationType().hashCode());
+ assertNotEquals(this.ip4caseADWrong.hashCode(), b.getAdvertizedRoutes().getDestinationType().hashCode());
- assertTrue(this.ip4caseAD.toString().equals(b.getAdvertizedRoutes().getDestinationType().toString()));
- assertFalse(this.ip4caseADWrong.toString().equals(b.getAdvertizedRoutes().getDestinationType().toString()));
+ assertEquals(this.ip4caseAD.toString(), b.getAdvertizedRoutes().getDestinationType().toString());
+ assertNotEquals(this.ip4caseADWrong.toString(), b.getAdvertizedRoutes().getDestinationType().toString());
}
@Test
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
+
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import java.util.ArrayList;
final LuOriginatorSrgbTlv parsed = parser.parseBgpPrefixSidTlv(serialized);
assertEquals(tlv.getSrgbValue().size(), parsed.getSrgbValue().size());
- assertTrue(tlv.getSrgbValue().get(0).getBase().equals(srgb1));
- assertTrue(tlv.getSrgbValue().get(0).getRange().equals(srgb2));
- assertTrue(tlv.getSrgbValue().get(1).getBase().equals(srgb2));
- assertTrue(tlv.getSrgbValue().get(1).getRange().equals(srgb1));
+ assertEquals(tlv.getSrgbValue().get(0).getBase(), srgb1);
+ assertEquals(tlv.getSrgbValue().get(0).getRange(), srgb2);
+ assertEquals(tlv.getSrgbValue().get(1).getBase(), srgb2);
+ assertEquals(tlv.getSrgbValue().get(1).getRange(), srgb1);
assertEquals(3, parser.getType());
}
@VisibleForTesting
public static final NodeIdentifier REMOTE_NODE_DESCRIPTORS_NID = new NodeIdentifier(RemoteNodeDescriptors.QNAME);
@VisibleForTesting
- public static final NodeIdentifier ADVERTISING_NODE_DESCRIPTORS_NID = new NodeIdentifier(AdvertisingNodeDescriptors.QNAME);
+ public static final NodeIdentifier ADVERTISING_NODE_DESCRIPTORS_NID
+ = new NodeIdentifier(AdvertisingNodeDescriptors.QNAME);
@VisibleForTesting
public static final NodeIdentifier PREFIX_DESCRIPTORS_NID = new NodeIdentifier(PrefixDescriptors.QNAME);
@VisibleForTesting
public static final NodeIdentifier LINK_DESCRIPTORS_NID = new NodeIdentifier(LinkDescriptors.QNAME);
@VisibleForTesting
- public static final NodeIdentifier PROTOCOL_ID_NID = new NodeIdentifier(QName.create(CLinkstateDestination.QNAME, "protocol-id").intern());
+ public static final NodeIdentifier PROTOCOL_ID_NID = new NodeIdentifier(
+ QName.create(CLinkstateDestination.QNAME.getModule(), "protocol-id"));
@VisibleForTesting
- public static final NodeIdentifier IDENTIFIER_NID = new NodeIdentifier(QName.create(CLinkstateDestination.QNAME, "identifier").intern());
+ public static final NodeIdentifier IDENTIFIER_NID = new NodeIdentifier(
+ QName.create(CLinkstateDestination.QNAME.getModule(), "identifier"));
@VisibleForTesting
- private static final NodeIdentifier DISTINGUISHER_NID = new NodeIdentifier(QName.create(CLinkstateDestination.QNAME, "route-distinguisher").intern());
+ private static final NodeIdentifier DISTINGUISHER_NID = new NodeIdentifier(
+ QName.create(CLinkstateDestination.QNAME.getModule(), "route-distinguisher"));
private final SimpleNlriTypeRegistry nlriTypeReg = SimpleNlriTypeRegistry.getInstance();
@Override
public void serializeAttribute(final DataObject attribute, final ByteBuf byteAggregator) {
- Preconditions.checkArgument(attribute instanceof Attributes, "Attribute parameter is not a PathAttribute object.");
+ Preconditions.checkArgument(attribute instanceof Attributes,
+ "Attribute parameter is not a PathAttribute object.");
final Attributes pathAttributes = (Attributes) attribute;
final Attributes1 pathAttributes1 = pathAttributes.getAugmentation(Attributes1.class);
final Attributes2 pathAttributes2 = pathAttributes.getAugmentation(Attributes2.class);
private void serializeWithDrawnRoutes(final WithdrawnRoutes withdrawnRoutes, final ByteBuf byteAggregator) {
if (withdrawnRoutes != null && withdrawnRoutes.getDestinationType() instanceof DestinationLinkstateCase) {
- final DestinationLinkstateCase linkstateCase = (DestinationLinkstateCase) withdrawnRoutes.getDestinationType();
- for (final CLinkstateDestination cLinkstateDestination : linkstateCase.getDestinationLinkstate().getCLinkstateDestination()) {
+ final DestinationLinkstateCase linkstateCase
+ = (DestinationLinkstateCase) withdrawnRoutes.getDestinationType();
+ for (final CLinkstateDestination cLinkstateDestination : linkstateCase.getDestinationLinkstate()
+ .getCLinkstateDestination()) {
this.nlriTypeReg.serializeNlriType(cLinkstateDestination, byteAggregator);
}
}
private void serializeAdvertisedRoutes(final AdvertizedRoutes advertizedRoutes, final ByteBuf byteAggregator) {
if (advertizedRoutes != null && advertizedRoutes.getDestinationType()
- instanceof
- org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationLinkstateCase) {
- final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationLinkstateCase
- linkstateCase = (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationLinkstateCase) advertizedRoutes.getDestinationType();
+ instanceof
+ org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.update
+ .attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationLinkstateCase) {
+ final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.update
+ .attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationLinkstateCase
+ linkstateCase = (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate
+ .rev180329.update.attributes.mp.reach.nlri.advertized.routes.destination.type
+ .DestinationLinkstateCase) advertizedRoutes.getDestinationType();
- for (final CLinkstateDestination cLinkstateDestination : linkstateCase.getDestinationLinkstate().getCLinkstateDestination()) {
+ for (final CLinkstateDestination cLinkstateDestination : linkstateCase.getDestinationLinkstate()
+ .getCLinkstateDestination()) {
this.nlriTypeReg.serializeNlriType(cLinkstateDestination, byteAggregator);
}
}
}
}
- public static CLinkstateDestination extractLinkstateDestination(final DataContainerNode<? extends PathArgument> linkstate) {
+ public static CLinkstateDestination extractLinkstateDestination(
+ final DataContainerNode<? extends PathArgument> linkstate) {
final CLinkstateDestinationBuilder builder = new CLinkstateDestinationBuilder();
serializeCommonParts(builder, linkstate);
return builder.build();
}
- private static void serializeNodeDescriptor(final CLinkstateDestinationBuilder builder, final ChoiceNode objectType) {
+ private static void serializeNodeDescriptor(final CLinkstateDestinationBuilder builder,
+ final ChoiceNode objectType) {
final NodeCaseBuilder nodeBuilder = new NodeCaseBuilder();
// node descriptors
nodeBuilder.setNodeDescriptors(NodeNlriParser
builder.setObjectType(nodeBuilder.build());
}
- private static void serializeLocalNodeDescriptor(final CLinkstateDestinationBuilder builder, final ChoiceNode objectType) {
+ private static void serializeLocalNodeDescriptor(final CLinkstateDestinationBuilder builder,
+ final ChoiceNode objectType) {
// link local node descriptors
final LinkCaseBuilder linkBuilder = new LinkCaseBuilder();
- linkBuilder.setLocalNodeDescriptors(NodeNlriParser.serializeLocalNodeDescriptors((ContainerNode) objectType.getChild(LOCAL_NODE_DESCRIPTORS_NID).get()));
+ linkBuilder.setLocalNodeDescriptors(NodeNlriParser.serializeLocalNodeDescriptors((ContainerNode) objectType
+ .getChild(LOCAL_NODE_DESCRIPTORS_NID).get()));
// link remote node descriptors
if (objectType.getChild(REMOTE_NODE_DESCRIPTORS_NID).isPresent()) {
- linkBuilder.setRemoteNodeDescriptors(NodeNlriParser.serializeRemoteNodeDescriptors((ContainerNode) objectType.getChild(REMOTE_NODE_DESCRIPTORS_NID).get()));
+ linkBuilder.setRemoteNodeDescriptors(NodeNlriParser
+ .serializeRemoteNodeDescriptors((ContainerNode) objectType.getChild(REMOTE_NODE_DESCRIPTORS_NID)
+ .get()));
}
// link descriptors
- final Optional<DataContainerChild<? extends PathArgument, ?>> linkDescriptors = objectType.getChild(LINK_DESCRIPTORS_NID);
- if (linkDescriptors.isPresent()) {
- linkBuilder.setLinkDescriptors(LinkNlriParser.serializeLinkDescriptors((ContainerNode) linkDescriptors.get()));
- }
+ final Optional<DataContainerChild<? extends PathArgument, ?>> linkDescriptors
+ = objectType.getChild(LINK_DESCRIPTORS_NID);
+ linkDescriptors.ifPresent(dataContainerChild -> linkBuilder.setLinkDescriptors(LinkNlriParser
+ .serializeLinkDescriptors((ContainerNode) dataContainerChild)));
builder.setObjectType(linkBuilder.build());
}
- private static void serializeAdvertisedNodeDescriptor(final CLinkstateDestinationBuilder builder, final ChoiceNode objectType) {
+ private static void serializeAdvertisedNodeDescriptor(final CLinkstateDestinationBuilder builder,
+ final ChoiceNode objectType) {
// prefix node descriptors
final PrefixCaseBuilder prefixBuilder = new PrefixCaseBuilder();
- prefixBuilder.setAdvertisingNodeDescriptors(NodeNlriParser.serializeAdvNodeDescriptors((ContainerNode) objectType.getChild(
- ADVERTISING_NODE_DESCRIPTORS_NID).get()));
+ prefixBuilder.setAdvertisingNodeDescriptors(NodeNlriParser
+ .serializeAdvNodeDescriptors((ContainerNode) objectType.getChild(ADVERTISING_NODE_DESCRIPTORS_NID)
+ .get()));
// prefix descriptors
- final Optional<DataContainerChild<? extends PathArgument, ?>> prefixDescriptors = objectType.getChild(PREFIX_DESCRIPTORS_NID);
- if (prefixDescriptors.isPresent()) {
- prefixBuilder.setPrefixDescriptors(AbstractPrefixNlriParser.serializePrefixDescriptors((ContainerNode) prefixDescriptors.get()));
- }
+ final Optional<DataContainerChild<? extends PathArgument, ?>> prefixDescriptors
+ = objectType.getChild(PREFIX_DESCRIPTORS_NID);
+ prefixDescriptors.ifPresent(dataContainerChild -> prefixBuilder.setPrefixDescriptors(AbstractPrefixNlriParser
+ .serializePrefixDescriptors((ContainerNode) dataContainerChild)));
builder.setObjectType(prefixBuilder.build());
}
- private static void serializeCommonParts(final CLinkstateDestinationBuilder builder, final DataContainerNode<? extends PathArgument> linkstate) {
+ private static void serializeCommonParts(final CLinkstateDestinationBuilder builder,
+ final DataContainerNode<? extends PathArgument> linkstate) {
// serialize common parts
- final Optional<DataContainerChild<? extends PathArgument, ?>> distinguisher = linkstate.getChild(DISTINGUISHER_NID);
- if (distinguisher.isPresent()) {
- builder.setRouteDistinguisher(RouteDistinguisherUtil.parseRouteDistinguisher(distinguisher.get().getValue()));
- }
+ final Optional<DataContainerChild<? extends PathArgument, ?>> distinguisher
+ = linkstate.getChild(DISTINGUISHER_NID);
+ distinguisher.ifPresent(dataContainerChild -> builder.setRouteDistinguisher(RouteDistinguisherUtil
+ .parseRouteDistinguisher(dataContainerChild.getValue())));
final Optional<DataContainerChild<? extends PathArgument, ?>> protocolId = linkstate.getChild(PROTOCOL_ID_NID);
// DOM representation contains values as are in the model, not as are in generated enum
- if (protocolId.isPresent()) {
- builder.setProtocolId(ProtocolId.forValue(domProtocolIdValue((String) protocolId.get().getValue())));
- }
+ protocolId.ifPresent(dataContainerChild -> builder.setProtocolId(ProtocolId
+ .forValue(domProtocolIdValue((String) dataContainerChild.getValue()))));
final Optional<DataContainerChild<? extends PathArgument, ?>> identifier = linkstate.getChild(IDENTIFIER_NID);
- if (identifier.isPresent()) {
- builder.setIdentifier(new Identifier((BigInteger) identifier.get().getValue()));
- }
+ identifier.ifPresent(dataContainerChild -> builder
+ .setIdentifier(new Identifier((BigInteger) dataContainerChild.getValue())));
}
}
@VisibleForTesting
private static final NodeIdentifier OSPF_PSEUDONODE_NID = new NodeIdentifier(OspfPseudonode.QNAME);
@VisibleForTesting
- public static final NodeIdentifier ISO_SYSTEM_NID = new NodeIdentifier(QName.create(NodeDescriptors.QNAME, "iso-system-id").intern());
+ public static final NodeIdentifier ISO_SYSTEM_NID = new NodeIdentifier(
+ QName.create(NodeDescriptors.QNAME.getModule(), "iso-system-id"));
@VisibleForTesting
- public static final NodeIdentifier ISIS_ROUTER_NID = new NodeIdentifier(QName.create(NodeDescriptors.QNAME, "is-is-router-identifier").intern());
+ public static final NodeIdentifier ISIS_ROUTER_NID = new NodeIdentifier(
+ QName.create(NodeDescriptors.QNAME.getModule(),"is-is-router-identifier"));
@VisibleForTesting
- public static final NodeIdentifier PSN_NID = new NodeIdentifier(QName.create(NodeDescriptors.QNAME, "psn").intern());
+ public static final NodeIdentifier PSN_NID = new NodeIdentifier(
+ QName.create(NodeDescriptors.QNAME.getModule(),"psn"));
@VisibleForTesting
- public static final NodeIdentifier OSPF_ROUTER_NID = new NodeIdentifier(QName.create(NodeDescriptors.QNAME, "ospf-router-id").intern());
- private static final NodeIdentifier LAN_IFACE_NID = new NodeIdentifier(QName.create(NodeDescriptors.QNAME, "lan-interface").intern());
+ public static final NodeIdentifier OSPF_ROUTER_NID = new NodeIdentifier(
+ QName.create(NodeDescriptors.QNAME.getModule(),"ospf-router-id"));
+ private static final NodeIdentifier LAN_IFACE_NID = new NodeIdentifier(
+ QName.create(NodeDescriptors.QNAME.getModule(),"lan-interface"));
@Override
protected ObjectType parseObjectType(final ByteBuf buffer) {
final NodeCaseBuilder builder = new NodeCaseBuilder();
- builder.setNodeDescriptors(new NodeDescriptorsBuilder((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.NodeIdentifier) SimpleNlriTypeRegistry.getInstance().parseTlv(buffer)).build());
+ builder.setNodeDescriptors(new NodeDescriptorsBuilder((org.opendaylight.yang.gen.v1.urn.opendaylight.params
+ .xml.ns.yang.bgp.linkstate.rev180329.NodeIdentifier) SimpleNlriTypeRegistry.getInstance()
+ .parseTlv(buffer)).build());
return builder.build();
}
if (pseudoIsisNode.getChild(ISIS_ROUTER_NID).isPresent()) {
final ContainerNode isisRouterNid = (ContainerNode) pseudoIsisNode.getChild(ISIS_ROUTER_NID).get();
if (isisRouterNid.getChild(ISO_SYSTEM_NID).isPresent()) {
- isisRouterId.setIsoSystemId(new IsoSystemIdentifier((byte[]) isisRouterNid.getChild(ISO_SYSTEM_NID).get().getValue()));
+ isisRouterId.setIsoSystemId(new IsoSystemIdentifier((byte[]) isisRouterNid.getChild(ISO_SYSTEM_NID)
+ .get().getValue()));
}
}
final OspfPseudonodeCaseBuilder builder = new OspfPseudonodeCaseBuilder();
final OspfPseudonodeBuilder nodeBuilder = new OspfPseudonodeBuilder();
if (ospfPseudonode.getChild(LAN_IFACE_NID).isPresent()) {
- nodeBuilder.setLanInterface(new OspfInterfaceIdentifier((Long)ospfPseudonode.getChild(LAN_IFACE_NID).get().getValue()));
+ nodeBuilder.setLanInterface(new OspfInterfaceIdentifier((Long)ospfPseudonode.getChild(LAN_IFACE_NID)
+ .get().getValue()));
}
if (ospfPseudonode.getChild(OSPF_ROUTER_NID).isPresent()) {
nodeBuilder.setOspfRouterId((Long)ospfPseudonode.getChild(OSPF_ROUTER_NID).get().getValue());
private static CRouterIdentifier serializeRouterId(final ContainerNode descriptorsData) {
CRouterIdentifier cRouterId = null;
- final Optional<DataContainerChild<? extends PathArgument, ?>> maybeRouterId = descriptorsData.getChild(ROUTER_NID);
+ final Optional<DataContainerChild<? extends PathArgument, ?>> maybeRouterId
+ = descriptorsData.getChild(ROUTER_NID);
if (maybeRouterId.isPresent()) {
final ChoiceNode routerId = (ChoiceNode) maybeRouterId.get();
if (routerId.getChild(ISIS_NODE_NID).isPresent()) {
}
private static AsNumber serializeAsNumber(final ContainerNode descriptorsData) {
- final Optional<DataContainerChild<? extends PathArgument, ?>> asNumber = descriptorsData.getChild(AS_NUMBER_NID);
- if (asNumber.isPresent()) {
- return new AsNumber((Long) asNumber.get().getValue());
- }
- return null;
+ final Optional<DataContainerChild<? extends PathArgument, ?>> asNumber
+ = descriptorsData.getChild(AS_NUMBER_NID);
+ return asNumber.map(dataContainerChild -> new AsNumber((Long) dataContainerChild.getValue())).orElse(null);
}
private static DomainIdentifier serializeDomainId(final ContainerNode descriptorsData) {
final Optional<DataContainerChild<? extends PathArgument, ?>> domainId = descriptorsData.getChild(DOMAIN_NID);
- if (domainId.isPresent()) {
- return new DomainIdentifier((Long) domainId.get().getValue());
- }
- return null;
+ return domainId.map(dataContainerChild
+ -> new DomainIdentifier((Long) dataContainerChild.getValue())).orElse(null);
}
private static AreaIdentifier serializeAreaId(final ContainerNode descriptorsData) {
final Optional<DataContainerChild<? extends PathArgument, ?>> areaId = descriptorsData.getChild(AREA_NID);
- if (areaId.isPresent()) {
- return new AreaIdentifier((Long) areaId.get().getValue());
- }
- return null;
+ return areaId.map(dataContainerChild
+ -> new AreaIdentifier((Long) dataContainerChild.getValue())).orElse(null);
}
private static Ipv4Address serializeBgpRouterId(final ContainerNode descriptorsData) {
- final Optional<DataContainerChild<? extends PathArgument, ?>> bgpRouterId = descriptorsData.getChild(BGP_ROUTER_NID);
- if (bgpRouterId.isPresent()) {
- return new Ipv4Address((String) bgpRouterId.get().getValue());
- }
- return null;
+ final Optional<DataContainerChild<? extends PathArgument, ?>> bgpRouterId
+ = descriptorsData.getChild(BGP_ROUTER_NID);
+ return bgpRouterId.map(dataContainerChild
+ -> new Ipv4Address((String) dataContainerChild.getValue())).orElse(null);
}
private static AsNumber serializeMemberAsn(final ContainerNode descriptorsData) {
- final Optional<DataContainerChild<? extends PathArgument, ?>> memberAsn = descriptorsData.getChild(MEMBER_ASN_NID);
- if (memberAsn.isPresent()) {
- return new AsNumber((Long) memberAsn.get().getValue());
- }
- return null;
+ final Optional<DataContainerChild<? extends PathArgument, ?>> memberAsn
+ = descriptorsData.getChild(MEMBER_ASN_NID);
+ return memberAsn.map(dataContainerChild -> new AsNumber((Long) dataContainerChild.getValue())).orElse(null);
}
static LocalNodeDescriptors serializeLocalNodeDescriptors(final ContainerNode descriptorsData) {
import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild;
-public final class OspfRouteTlvParser implements LinkstateTlvParser<OspfRouteType>, LinkstateTlvParser.LinkstateTlvSerializer<OspfRouteType> {
+public final class OspfRouteTlvParser implements LinkstateTlvParser<OspfRouteType>,
+ LinkstateTlvParser.LinkstateTlvSerializer<OspfRouteType> {
- public static final QName OSPF_ROUTE_TYPE_QNAME = QName.create(PrefixDescriptors.QNAME, "ospf-route-type").intern();
+ public static final QName OSPF_ROUTE_TYPE_QNAME =
+ QName.create(PrefixDescriptors.QNAME.getModule(), "ospf-route-type");
public static final NodeIdentifier OSPF_ROUTE_NID = new NodeIdentifier(OspfRouteTlvParser.OSPF_ROUTE_TYPE_QNAME);
private static final int OSPF_ROUTE_TYPE = 264;
}
public static OspfRouteType serializeModel(final ContainerNode prefixDesc) {
- final Optional<DataContainerChild<? extends YangInstanceIdentifier.PathArgument, ?>> ospfRoute = prefixDesc.getChild(OSPF_ROUTE_NID);
- if (ospfRoute.isPresent()) {
- return OspfRouteType.forValue(domOspfRouteTypeValue((String) ospfRoute.get().getValue()));
- }
- return null;
+ final Optional<DataContainerChild<? extends YangInstanceIdentifier.PathArgument, ?>> ospfRoute
+ = prefixDesc.getChild(OSPF_ROUTE_NID);
+ return ospfRoute.map(dataContainerChild
+ -> OspfRouteType.forValue(domOspfRouteTypeValue((String) dataContainerChild.getValue())))
+ .orElse(null);
}
= new HashMap<>();
//TODO Implement match prefix
//private final GenericConditionPolicyHandler genericConditionHandler;
- private BgpConditionsRegistry bgpConditionsRegistry = new BgpConditionsRegistry();
+ private final BgpConditionsRegistry bgpConditionsRegistry = new BgpConditionsRegistry();
ConditionsRegistryImpl(final DataBroker databroker) {
// this.genericConditionHandler = new GenericConditionPolicyHandler(databroker);
private static AfiSafi buildAfiSafi(@Nonnull final BGPAfiSafiState neighbor,
@Nonnull final TablesKey tablesKey, @Nonnull final BGPTableTypeRegistryConsumer bgpTableTypeRegistry) {
final Optional<Class<? extends AfiSafiType>> afiSafi = bgpTableTypeRegistry.getAfiSafiType(tablesKey);
- if (!afiSafi.isPresent()) {
- return null;
- }
-
- return new AfiSafiBuilder().setAfiSafiName(afiSafi.get())
+ return afiSafi.map(aClass -> new AfiSafiBuilder().setAfiSafiName(aClass)
.setState(buildAfiSafiState(neighbor, tablesKey, neighbor.isAfiSafiSupported(tablesKey)))
- .setGracefulRestart(buildAfiSafiGracefulRestartState(neighbor, tablesKey)).build();
+ .setGracefulRestart(buildAfiSafiGracefulRestartState(neighbor, tablesKey)).build()).orElse(null);
+
}
private static org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.multiprotocol.rev151009.bgp.common.afi
private InMemoryDOMDataStore spiedOperStore;
@Before
- public void setUp() throws Exception {
+ public void setUp() {
MockitoAnnotations.initMocks(this);
doReturn(Optional.of(IPV4UNICAST.class))
}).when(mockTxChain).newWriteOnlyTransaction();
return mockTxChain;
- }).doAnswer(invocation -> {
- return realOperStore.createTransactionChain();
- }).when(spiedOperStore).createTransactionChain();
+ }).doAnswer(invocation -> realOperStore.createTransactionChain()).when(spiedOperStore).createTransactionChain();
int timerInterval = 1;
try (StateProviderImpl stateProvider = new StateProviderImpl(getDataBroker(), timerInterval, tableTypeRegistry,
package org.opendaylight.protocol.bgp.parser;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
import java.util.ArrayList;
import java.util.List;
BgpExtendedMessageUtil.EXTENDED_MESSAGE_CAPABILITY).build());
params.add(new BgpParametersBuilder().setOptionalCapabilities(capas).build());
final Open open1 = new OpenBuilder().setBgpParameters(params).build();
- assertEquals(true, BgpExtendedMessageUtil.advertizedBgpExtendedMessageCapability(open1));
+ assertTrue(BgpExtendedMessageUtil.advertizedBgpExtendedMessageCapability(open1));
}
}
package org.opendaylight.protocol.bgp.parser;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.fail;
assertEquals("Subsequent address family may not be null", e.getMessage());
}
- assertFalse(tt1.equals(tt2));
+ assertNotEquals(tt1, tt2);
assertNotSame(tt1.hashCode(), tt2.hashCode());
assertEquals(tt1.toString(), tt1.toString());
assertNotSame(tt1.getAfi(), tt2.getAfi());
private final AddressFamilyRegistry afiReg;
private final SubsequentAddressFamilyRegistry safiReg;
- public MultiProtocolCapabilityHandler(final AddressFamilyRegistry afiReg, final SubsequentAddressFamilyRegistry safiReg) {
+ public MultiProtocolCapabilityHandler(final AddressFamilyRegistry afiReg,
+ final SubsequentAddressFamilyRegistry safiReg) {
this.afiReg = requireNonNull(afiReg);
this.safiReg = requireNonNull(safiReg);
}
@Override
public CParameters parseCapability(final ByteBuf buffer) throws BGPDocumentedException, BGPParsingException {
- final Optional<BgpTableType> parsedAfiSafiOptional = MultiprotocolCapabilitiesUtil.parseMPAfiSafi(buffer, this.afiReg, this.safiReg);
- if (!parsedAfiSafiOptional.isPresent()) {
- return null;
- }
- return new CParametersBuilder().addAugmentation(CParameters1.class,new CParameters1Builder().setMultiprotocolCapability(
- new MultiprotocolCapabilityBuilder(parsedAfiSafiOptional.get()).build()).build()).build();
+ final Optional<BgpTableType> parsedAfiSafiOptional = MultiprotocolCapabilitiesUtil
+ .parseMPAfiSafi(buffer, this.afiReg, this.safiReg);
+ return parsedAfiSafiOptional.map(bgpTableType -> new CParametersBuilder()
+ .addAugmentation(CParameters1.class, new CParameters1Builder().setMultiprotocolCapability(
+ new MultiprotocolCapabilityBuilder(bgpTableType).build()).build()).build()).orElse(null);
}
@Override
final MultiprotocolCapability mp = capability.getAugmentation(CParameters1.class).getMultiprotocolCapability();
final ByteBuf capBuffer = Unpooled.buffer();
- MultiprotocolCapabilitiesUtil.serializeMPAfiSafi(this.afiReg, this.safiReg, mp.getAfi(), mp.getSafi(), capBuffer);
+ MultiprotocolCapabilitiesUtil.serializeMPAfiSafi(this.afiReg, this.safiReg, mp.getAfi(),
+ mp.getSafi(), capBuffer);
CapabilityUtil.formatCapability(CODE, capBuffer, byteAggregator);
}
*/
static final List<byte[]> inputBytes = new ArrayList<>();
- private static int COUNTER = 7;
+ private static final int COUNTER = 7;
- private static int MAX_SIZE = 300;
+ private static final int MAX_SIZE = 300;
private static BGPUpdateMessageParser updateParser;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotSame;
import java.lang.reflect.Constructor;
assertEquals(0, tlv3.getRestartTime().intValue());
- assertFalse(tlv1.equals(tlv2));
+ assertNotEquals(tlv1, tlv2);
assertNotSame(tlv1.hashCode(), tlv3.hashCode());
public void testHashCodeAndEqual() {
assertTrue(this.baseBestPath.equals(this.baseBestPathCopy)
&& this.baseBestPathCopy.equals(this.baseBestPath));
- assertTrue(this.baseBestPath.hashCode() == this.baseBestPathCopy.hashCode());
+ assertEquals(this.baseBestPath.hashCode(), this.baseBestPathCopy.hashCode());
}
@Test
this.writerChain = this.rib.createPeerDOMChain(this);
final Set<TablesKey> localTables = this.rib.getLocalTablesKeys();
- localTables.forEach(tablesKey -> {
- this.supportedTables.add(RibSupportUtils.toYangTablesKey(tablesKey));
- });
+ localTables.forEach(tablesKey -> this.supportedTables.add(RibSupportUtils.toYangTablesKey(tablesKey)));
setAdvertizedGracefulRestartTableTypes(Collections.emptyList());
this.adjRibInWriter = AdjRibInWriter.create(this.rib.getYangRibId(), PeerRole.Internal, this.writerChain);
@GuardedBy("this")
private BGPSession session;
@GuardedBy("this")
- private DOMTransactionChain chain;
+ private final DOMTransactionChain chain;
@GuardedBy("this")
private AdjRibInWriter ribWriter;
@GuardedBy("this")
public final class BGPPeerTrackerImpl implements BGPPeerTracker {
@GuardedBy("this")
- private Map<PeerId, Peer> peers = new HashMap<>();
+ private final Map<PeerId, Peer> peers = new HashMap<>();
private ImmutableList<Peer> peersList;
@Override
}
private final class BgpPeerSingletonService implements BGPPeerStateConsumer {
- private boolean activeConnection;
+ private final boolean activeConnection;
private final BGPDispatcher dispatcher;
private final InetSocketAddress inetAddress;
private final int retryTimer;
private Ipv4Address routerId;
private ClusterIdentifier clusterId;
- private DataBroker dataBroker;
+ private final DataBroker dataBroker;
public RibImpl(
final RIBExtensionConsumerContext contextProvider,
private NioEventLoopGroup boss;
private org.opendaylight.protocol.bgp.inet.BGPActivator inetActivator;
protected StrictBGPPeerRegistry serverRegistry;
- protected BGPPeerTrackerImpl peerTracker = new BGPPeerTrackerImpl();
+ protected final BGPPeerTrackerImpl peerTracker = new BGPPeerTrackerImpl();
protected CodecsRegistryImpl codecsRegistry;
@Before
@Mock
private ClusterSingletonServiceProvider clusterSingletonServiceProvider;
- private BGPPeerTracker peerTracker = new BGPPeerTrackerImpl();
+ private final BGPPeerTracker peerTracker = new BGPPeerTrackerImpl();
private static ModuleInfoBackedContext createClassLoadingStrategy() {
final ModuleInfoBackedContext ctx = ModuleInfoBackedContext.create();
*/
package org.opendaylight.protocol.bgp.rib.impl;
+import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.any;
@Mock
private BGPDispatcher dispatcher;
- private BGPPeerTracker peerTracker = new BGPPeerTrackerImpl();
+ private final BGPPeerTracker peerTracker = new BGPPeerTrackerImpl();
private CodecsRegistryImpl codecsRegistry;
@Before
for (final Tables table : tables) {
if (table.getAfi().equals(tableType.getAfi()) && table.getSafi().equals(tableType.getSafi())) {
found = true;
- assertTrue(Boolean.valueOf(true).equals(table.getAttributes().isUptodate()));
+ assertEquals(Boolean.valueOf(true), table.getAttributes().isUptodate());
}
}
assertTrue(found);
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertNotEquals;
import com.google.common.primitives.UnsignedInteger;
import org.junit.Test;
final RouteUpdateKey rk = new RouteUpdateKey(PEER_ID, PREFIX);
assertEquals(PEER_ID, rk.getPeerId());
assertEquals(PREFIX, rk.getRouteId());
- assertTrue(rk.equals(new RouteUpdateKey(PEER_ID, PREFIX)));
- assertTrue(rk.equals(rk));
+ assertEquals(rk, new RouteUpdateKey(PEER_ID, PREFIX));
+ assertEquals(rk, rk);
assertFalse(rk.equals(null));
- assertFalse(rk.equals(new RouteUpdateKey(PEER_ID_2, PREFIX)));
- assertFalse(rk.equals(new RouteUpdateKey(PEER_ID_2, PREFIX_2)));
+ assertNotEquals(rk, new RouteUpdateKey(PEER_ID_2, PREFIX));
+ assertNotEquals(rk, new RouteUpdateKey(PEER_ID_2, PREFIX_2));
}
}
\ No newline at end of file
}
BGPSessionImpl getSession() {
- Assert.assertEquals("Session up", true, Uninterruptibles.awaitUninterruptibly(this.sessionLatch, 10, TimeUnit.SECONDS));
+ Assert.assertTrue("Session up", Uninterruptibles.awaitUninterruptibly(this.sessionLatch, 10, TimeUnit.SECONDS));
return (BGPSessionImpl) this.session;
}
protected PeerGroupConfigLoader peerGroupLoader;
@Mock
private DOMDataTreeChangeService dataTreeChangeService;
- private BGPPeerTracker peerTracker = new BGPPeerTrackerImpl();
+ private final BGPPeerTracker peerTracker = new BGPPeerTrackerImpl();
@Before
public void setUp() throws Exception {
private DataTreeCandidateNode subTree;
private DOMDataWriteTransaction tx;
private ContainerNode nlri;
- private Map<YangInstanceIdentifier, NormalizedNode<?, ?>> routesMap = new HashMap<>();
+ private final Map<YangInstanceIdentifier, NormalizedNode<?, ?>> routesMap = new HashMap<>();
private ContainerNode attributes;
private MapEntryNode mapEntryNode;
private BindingToNormalizedNodeCodec mappingService;
public class RouterIdsTest {
- private UnsignedInteger unsignedRouterId = UnsignedInteger.valueOf(707406378);
- private PeerId peerID = new PeerId("bgp://42.42.42.42");
+ private final UnsignedInteger unsignedRouterId = UnsignedInteger.valueOf(707406378);
+ private final PeerId peerID = new PeerId("bgp://42.42.42.42");
@Test
public void testRouterIdForAddress() throws Exception {
private ListenerRegistration<AbstractTopologyBuilder<T>> listenerRegistration = null;
@GuardedBy("this")
private BindingTransactionChain chain = null;
- private AtomicBoolean closed = new AtomicBoolean(false);
+ private final AtomicBoolean closed = new AtomicBoolean(false);
@GuardedBy("this")
@VisibleForTesting
protected long listenerScheduledRestartTime = 0;
*/
package org.opendaylight.bgpcep.bgp.topology.provider;
-import com.google.common.collect.Lists;
import com.google.common.io.BaseEncoding;
import java.math.BigDecimal;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.List;
+import java.util.stream.Collectors;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.IsisAreaIdentifier;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.NodeFlagBits;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.NodeIdentifier;
private static List<IsoNetId> toIsoNetIds(final List<IsisAreaIdentifier> areaIds, final String systemId) {
- return Lists.transform(areaIds, input -> new IsoNetId(UriBuilder.toIsoNetId(input, systemId)));
+ return areaIds.stream().map(input -> new IsoNetId(UriBuilder.toIsoNetId(input, systemId)))
+ .collect(Collectors.toList());
}
private static List<Short> nodeMultiTopology(final List<TopologyIdentifier> list) {
.child(Tables.class, new TablesKey(LinkstateAddressFamily.class, LinkstateSubsequentAddressFamily.class))
.build();
this.linkstateRouteIID = path.builder().child((Class) LinkstateRoutes.class)
- .child(LinkstateRoute.class, new LinkstateRouteKey(new PathId(0L), LINKSTATE_ROUTE_KEY.toString()))
+ .child(LinkstateRoute.class, new LinkstateRouteKey(new PathId(0L), LINKSTATE_ROUTE_KEY))
.build();
}
Thread.sleep(LISTENER_RESTART_TIME);
// manually invoke onTransactionChainFailed() to have the listener restart scheduled again
spiedLinkstateTopologyBuilder.onTransactionChainFailed(null, null, null);
- assertTrue(spiedLinkstateTopologyBuilder.listenerScheduledRestartTime == listenerScheduledRestartTime
+ assertEquals(spiedLinkstateTopologyBuilder.listenerScheduledRestartTime, listenerScheduledRestartTime
+ LISTENER_RESTART_TIME);
verify(spiedLinkstateTopologyBuilder, times(5)).restartTransactionChainOnDemand();
verify(spiedLinkstateTopologyBuilder, times(3)).scheduleListenerRestart();
private final BmpSessionListenerFactory slf;
private final KeyMapping keys;
private long delay;
- private Timer timer = new Timer();
+ private final Timer timer = new Timer();
BootstrapListener(final Bootstrap bootstrap,
final InetSocketAddress remoteAddress, final BmpSessionListenerFactory slf, final KeyMapping keys) {
private final Bootstrap bootstrap;
private final InetSocketAddress remoteAddress;
private final SocketAddress localAddress;
- private long delay;
- private Timer timer = new Timer();
+ private final long delay;
+ private final Timer timer = new Timer();
BootstrapListener(final Bootstrap bootstrap, final SocketAddress localAddress,
final InetSocketAddress remoteAddress) {
public final class BmpMockSessionListener implements BmpSessionListener {
private final LongAdder counter = new LongAdder();
@GuardedBy("this")
- private AtomicBoolean up = new AtomicBoolean(false);
+ private final AtomicBoolean up = new AtomicBoolean(false);
@Override
public void onSessionUp(final BmpSession session) {
@Override
protected void addTlv(final TlvsBuilder builder, final Tlv tlv) {
- if (tlv != null && tlv instanceof DescriptionTlv) {
+ if (tlv instanceof DescriptionTlv) {
builder.setDescriptionTlv((DescriptionTlv) tlv);
}
}
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.not;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertThat;
import java.util.HashSet;
assertThat(this.asn1, not(equalTo(this.asn3)));
assertThat(this.asn1, not(equalTo(this.asn4)));
assertThat(this.asn1, not(equalTo(new Object())));
- assertFalse(this.asn1.equals(new Object()));
+ assertNotEquals(this.asn1, new Object());
}
@Test
<classifier>features</classifier>
<type>xml</type>
</dependency>
- <dependency>
- <groupId>${project.groupId}</groupId>
- <artifactId>odl-bgpcep-bgp-mvpn</artifactId>
- <classifier>features</classifier>
- <type>xml</type>
- </dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>odl-bgpcep-bgp-l3vpn</artifactId>
private static final int PREFIX_F_LENGTH = 1;
private static final int FLAGS_SIZE = 8;
- private static final int PREFIX4_F_OFFSET = 0 + Ipv4Util.IP4_LENGTH;
+ private static final int PREFIX4_F_OFFSET = Ipv4Util.IP4_LENGTH;
private static final int CONTENT4_LENGTH = Ipv4Util.IP4_LENGTH + PREFIX_F_LENGTH + FLAGS_SIZE / Byte.SIZE;
// True if the listener should not be notified about events
@GuardedBy("this")
- private AtomicBoolean closed = new AtomicBoolean(false);
+ private final AtomicBoolean closed = new AtomicBoolean(false);
private final Channel channel;
*/
public class SimpleSessionListener implements PCEPSessionListener {
- public List<Message> messages = Lists.newArrayList();
+ public final List<Message> messages = Lists.newArrayList();
public boolean up = false;
}
public PCEPSession getSession() {
- Assert.assertEquals("Session up", true,
- Uninterruptibles.awaitUninterruptibly(this.sessionLatch, 10, TimeUnit.SECONDS));
+ Assert.assertTrue("Session up", Uninterruptibles.awaitUninterruptibly(this.sessionLatch, 10, TimeUnit.SECONDS));
return this.session;
}
assertNull(header.isProcessingRule());
assertEquals(new ObjectHeaderImpl(null, true).hashCode(), header.hashCode());
- assertTrue(new ObjectHeaderImpl(null, true).equals(header));
+ assertEquals(new ObjectHeaderImpl(null, true), header);
}
@Test
public final List<AutoCloseable> regs = new ArrayList<>();
- AbstractPCEPExtensionProviderActivator activator = new AbstractPCEPExtensionProviderActivator() {
+ final AbstractPCEPExtensionProviderActivator activator = new AbstractPCEPExtensionProviderActivator() {
@Override
protected List<AutoCloseable> startImpl(final PCEPExtensionProviderContext context) {
}
};
- PCEPExtensionProviderContext ctx = ServiceLoaderPCEPExtensionProviderContext.getSingletonInstance();
+ final PCEPExtensionProviderContext ctx = ServiceLoaderPCEPExtensionProviderContext.getSingletonInstance();
@Before
public void setUp() throws PCEPDeserializerException {
*/
public class SimpleSessionListener implements PCEPSessionListener {
- private List<Message> messages = Lists.newArrayList();
+ private final List<Message> messages = Lists.newArrayList();
private static final Logger LOG = LoggerFactory.getLogger(SimpleSessionListener.class);
private InstanceIdentifier<PathComputationClient> pccIdentifier;
@GuardedBy("this")
private TopologyNodeState nodeState;
- private AtomicBoolean synced = new AtomicBoolean(false);
+ private final AtomicBoolean synced = new AtomicBoolean(false);
@GuardedBy("this")
private PCEPSession session;
@GuardedBy("this")
import com.google.common.util.concurrent.ListenableFuture;
import java.util.Collections;
import java.util.List;
+import java.util.stream.Collectors;
import org.opendaylight.protocol.pcep.spi.PCEPErrors;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcep.error.object.ErrorObjectBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcerr.message.pcerr.message.Errors;
public static OperationResults createUnsent(final PCEPErrors error) {
final List<Errors> e = error != null ? Collections.singletonList(getErrorFor(error))
: Collections.emptyList();
- return new OperationResults(FailureType.Unsent, Lists.transform(e, CONVERT_ERRORS));
+ return new OperationResults(FailureType.Unsent, e.stream().map(CONVERT_ERRORS::apply)
+ .collect(Collectors.toList()));
}
private static Errors getErrorFor(final PCEPErrors error) {
@GuardedBy("this")
private final List<PlspId> staleLsps = new ArrayList<>();
- private AtomicBoolean statefulCapability = new AtomicBoolean(false);
- private AtomicBoolean lspUpdateCapability = new AtomicBoolean(false);
- private AtomicBoolean initiationCapability = new AtomicBoolean(false);
+ private final AtomicBoolean statefulCapability = new AtomicBoolean(false);
+ private final AtomicBoolean lspUpdateCapability = new AtomicBoolean(false);
+ private final AtomicBoolean initiationCapability = new AtomicBoolean(false);
/**
* Creates a new stateful topology session listener for given server session manager.
doReturn(dependencies).when(mockedSubmitInstruction).getPreconditions();
doReturn(new InstructionId(id)).when(mockedSubmitInstruction).getId();
- doReturn(deadline.isPresent() ? deadline.get() : new Nanotime(BigInteger.valueOf(Long.MAX_VALUE)))
+ doReturn(deadline.orElseGet(() -> new Nanotime(BigInteger.valueOf(Long.MAX_VALUE))))
.when(mockedSubmitInstruction).getDeadline();
return mockedSubmitInstruction;
}
import java.net.InetSocketAddress;
import java.util.Arrays;
import java.util.List;
+import java.util.stream.Collectors;
/**
* Created as a util for test tools.
}
public static List<InetSocketAddress> parseAddresses(final String address, final int defaultPort) {
- return Lists.transform(Arrays.asList(address.split(SEPARATOR)),
- input -> getInetSocketAddress(input, defaultPort));
+ return Arrays.asList(address.split(SEPARATOR)).stream()
+ .map(input -> getInetSocketAddress(input, defaultPort)).collect(Collectors.toList());
}
public static List<InetSocketAddress> parseAddresses(final String address) {
import static junit.framework.TestCase.assertNull;
import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.doReturn;
private final KeyedInstanceIdentifier<Topology, TopologyKey> topologyIIdKeyed =
InstanceIdentifier.create(NetworkTopology.class).child(Topology.class,
new TopologyKey(TOPOLOGY_ID));
- private static int TIMEOUT = 1;
+ private static final int TIMEOUT = 1;
@Mock
private ListenerCheck listenerCheck;
@Mock
@Test(expected = AssertionError.class)
public void testCheckEquals() throws Exception {
- checkEquals(() -> assertTrue(false), TIMEOUT);
+ checkEquals(() -> fail(), TIMEOUT);
}
@Test(expected = AssertionError.class)
final String FILE_TO_TEST = "src/test/resources/PCEStatefulCapabilityTlv1.bin";
final File fileToCompareWith = new File(FILE_TO_TEST);
- final InputStream bytesIStream = new FileInputStream(fileToCompareWith);
- try {
+ try (InputStream bytesIStream = new FileInputStream(fileToCompareWith)) {
final byte[] actualBytes = ByteArray.fileToBytes(FILE_TO_TEST);
if (fileToCompareWith.length() > Integer.MAX_VALUE) {
}
assertArrayEquals(expectedBytes, actualBytes);
- } finally {
- bytesIStream.close();
}
}