this.flowspecTypeRegistry = requireNonNull(flowspecTypeRegistry);
}
- protected abstract void serializeMpReachNlri(final DestinationType dstType, final ByteBuf byteAggregator);
+ protected abstract void serializeMpReachNlri(DestinationType dstType, ByteBuf byteAggregator);
- protected abstract void serializeMpUnreachNlri(final DestinationType dstType, final ByteBuf byteAggregator);
+ protected abstract void serializeMpUnreachNlri(DestinationType dstType, ByteBuf byteAggregator);
- public abstract void extractSpecificFlowspec(final ChoiceNode fsType, final FlowspecBuilder fsBuilder);
+ public abstract void extractSpecificFlowspec(ChoiceNode fsType, FlowspecBuilder fsBuilder);
- protected abstract void stringSpecificFSNlriType(final FlowspecType value, final StringBuilder buffer);
+ protected abstract void stringSpecificFSNlriType(FlowspecType value, StringBuilder buffer);
/**
- * Create withdrawn destination type
+ * Create withdrawn destination type.
*
* @param nlriFields a list of NLRI fields to be included in the destination type
* @param pathId associated path id with given NLRI
@Nullable PathId pathId);
/**
- * Create advertized destination type
+ * Create advertized destination type.
*
* @param nlriFields a list of NLRI fields to be included in the destination type
* @param pathId associated path id with given NLRI
* @return created destination type
*/
- public abstract DestinationType createAdvertizedRoutesDestinationType(@Nonnull Object[] nlriFields, @Nullable PathId pathId);
+ public abstract DestinationType createAdvertizedRoutesDestinationType(@Nonnull Object[] nlriFields,
+ @Nullable PathId pathId);
@Override
public final void serializeAttribute(final Attributes pathAttributes, final ByteBuf byteAggregator) {
* Serializes Flowspec NLRI to ByteBuf.
*
* @param nlriFields NLRI fields to be serialized
- * @param pathId
- * @param buffer where flowspec NLRI will be serialized
+ * @param pathId path ID
+ * @param buffer where flowspec NLRI will be serialized
*/
protected final void serializeNlri(@Nonnull final Object[] nlriFields, @Nullable final PathId pathId,
@Nonnull final ByteBuf buffer) {
return stringNlri(extractFlowspec(flowspec));
}
+ protected final String stringNlri(final List<Flowspec> flows) {
+ final StringBuilder buffer = new StringBuilder("all packets ");
+ final Joiner joiner = Joiner.on(FLOW_SEPARATOR);
+ joiner.appendTo(buffer, flows.stream().map(this::encodeFlow).collect(Collectors.toList()));
+ return buffer.toString().replace(" ", " ");
+ }
+
public final List<Flowspec> extractFlowspec(final DataContainerNode<?> route) {
requireNonNull(route, "Cannot extract flowspec from null route.");
final List<Flowspec> fsList = new ArrayList<>();
for (final UnkeyedListEntryNode node : portsData.getValue()) {
final PortsBuilder portsBuilder = new PortsBuilder();
- final Optional<DataContainerChild<? extends PathArgument, ?>> opValue = node.getChild(OP_NID);
- opValue.ifPresent(dataContainerChild -> portsBuilder
- .setOp(NumericTwoByteOperandParser.INSTANCE.create((Set<String>) dataContainerChild.getValue())));
+ node.getChild(OP_NID).ifPresent(
+ dataContainerChild -> portsBuilder.setOp(NumericTwoByteOperandParser.INSTANCE.create(
+ (Set<String>) dataContainerChild.getValue())));
final Optional<DataContainerChild<? extends PathArgument, ?>> valueNode = node.getChild(VALUE_NID);
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);
- opValue.ifPresent(dataContainerChild -> destPortsBuilder.setOp(NumericTwoByteOperandParser
- .INSTANCE.create((Set<String>) dataContainerChild.getValue())));
- final Optional<DataContainerChild<? extends PathArgument, ?>> valueNode = node.getChild(VALUE_NID);
- valueNode.ifPresent(dataContainerChild
- -> destPortsBuilder.setValue((Integer) dataContainerChild.getValue()));
+ node.getChild(OP_NID).ifPresent(dataContainerChild -> destPortsBuilder.setOp(
+ NumericTwoByteOperandParser.INSTANCE.create((Set<String>) dataContainerChild.getValue())));
+ node.getChild(VALUE_NID).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);
- opValue.ifPresent(dataContainerChild -> sourcePortsBuilder.setOp(NumericTwoByteOperandParser
- .INSTANCE.create((Set<String>) dataContainerChild.getValue())));
- final Optional<DataContainerChild<? extends PathArgument, ?>> valueNode = node.getChild(VALUE_NID);
- valueNode.ifPresent(dataContainerChild
- -> sourcePortsBuilder.setValue((Integer) dataContainerChild.getValue()));
+ node.getChild(OP_NID).ifPresent(dataContainerChild -> sourcePortsBuilder.setOp(
+ NumericTwoByteOperandParser.INSTANCE.create((Set<String>) dataContainerChild.getValue())));
+ node.getChild(VALUE_NID).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);
- opValue.ifPresent(dataContainerChild -> typesBuilder.setOp(NumericOneByteOperandParser
- .INSTANCE.create((Set<String>) dataContainerChild.getValue())));
+ node.getChild(OP_NID).ifPresent(dataContainerChild -> typesBuilder.setOp(
+ NumericOneByteOperandParser.INSTANCE.create((Set<String>) dataContainerChild.getValue())));
final Optional<DataContainerChild<? extends PathArgument, ?>> valueNode = node.getChild(VALUE_NID);
valueNode.ifPresent(dataContainerChild -> typesBuilder.setValue((Short) dataContainerChild.getValue()));
types.add(typesBuilder.build());
for (final UnkeyedListEntryNode node : tcpFlagsData.getValue()) {
final TcpFlagsBuilder tcpFlagsBuilder = new TcpFlagsBuilder();
- final Optional<DataContainerChild<? extends PathArgument, ?>> opValue = node.getChild(OP_NID);
- opValue.ifPresent(dataContainerChild -> tcpFlagsBuilder
+ node.getChild(OP_NID).ifPresent(dataContainerChild -> tcpFlagsBuilder
.setOp(BitmaskOperandParser.INSTANCE.create((Set<String>) dataContainerChild.getValue())));
- final Optional<DataContainerChild<? extends PathArgument, ?>> valueNode = node.getChild(VALUE_NID);
- valueNode.ifPresent(dataContainerChild
- -> tcpFlagsBuilder.setValue((Integer) dataContainerChild.getValue()));
+ node.getChild(VALUE_NID).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);
- opValue.ifPresent(dataContainerChild -> packetLengthsBuilder.setOp(NumericTwoByteOperandParser
- .INSTANCE.create((Set<String>) dataContainerChild.getValue())));
- final Optional<DataContainerChild<? extends PathArgument, ?>> valueNode = node.getChild(VALUE_NID);
- valueNode.ifPresent(dataContainerChild
- -> packetLengthsBuilder.setValue((Integer) dataContainerChild.getValue()));
+ node.getChild(OP_NID).ifPresent(dataContainerChild -> packetLengthsBuilder.setOp(
+ NumericTwoByteOperandParser.INSTANCE.create((Set<String>) dataContainerChild.getValue())));
+ node.getChild(VALUE_NID).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);
- opValue.ifPresent(dataContainerChild -> dscpsLengthsBuilder.setOp(NumericOneByteOperandParser
- .INSTANCE.create((Set<String>) dataContainerChild.getValue())));
- final Optional<DataContainerChild<? extends PathArgument, ?>> valueNode = node.getChild(VALUE_NID);
- valueNode.ifPresent(dataContainerChild
- -> dscpsLengthsBuilder.setValue(new Dscp((Short) dataContainerChild.getValue())));
+ node.getChild(OP_NID).ifPresent(dataContainerChild -> dscpsLengthsBuilder.setOp(
+ NumericOneByteOperandParser.INSTANCE.create((Set<String>) dataContainerChild.getValue())));
+ node.getChild(VALUE_NID).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);
- opValue.ifPresent(dataContainerChild -> fragmentsBuilder.setOp(BitmaskOperandParser
- .INSTANCE.create((Set<String>) dataContainerChild.getValue())));
- final Optional<DataContainerChild<? extends PathArgument, ?>> valueNode = node.getChild(VALUE_NID);
- valueNode.ifPresent(dataContainerChild
- -> fragmentsBuilder.setValue(createFragment((Set<String>) dataContainerChild.getValue())));
+ node.getChild(OP_NID).ifPresent(dataContainerChild -> fragmentsBuilder.setOp(
+ BitmaskOperandParser.INSTANCE.create((Set<String>) dataContainerChild.getValue())));
+ node.getChild(VALUE_NID).ifPresent(dataContainerChild -> fragmentsBuilder.setValue(
+ createFragment((Set<String>) dataContainerChild.getValue())));
fragments.add(fragmentsBuilder.build());
}
data.contains(LAST_VALUE));
}
- protected final String stringNlri(final List<Flowspec> flows) {
- final StringBuilder buffer = new StringBuilder("all packets ");
- final Joiner joiner = Joiner.on(FLOW_SEPARATOR);
- joiner.appendTo(buffer, flows.stream().map(this::encodeFlow).collect(Collectors.toList()));
- return buffer.toString().replace(" ", " ");
- }
-
@VisibleForTesting
final String encodeFlow(final Flowspec flow) {
final StringBuilder buffer = new StringBuilder();
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()));
}
/**
- * Override this function to parse additional NLRI fields
+ * Override this function to parse additional NLRI fields.
*
* @param nlri NLRI buffer
* @return Parsed additional fields
@Override
public final void parseNlri(@Nonnull final ByteBuf nlri, @Nonnull final MpReachNlriBuilder builder,
- @Nullable final PeerSpecificParserConstraint constraint)
- throws BGPParsingException {
+ @Nullable final PeerSpecificParserConstraint constraint) throws BGPParsingException {
if (!nlri.isReadable()) {
return;
}
);
}
- @Nullable
- protected static PathId readPathId(@Nonnull final ByteBuf nlri, final Class<? extends AddressFamily> afi,
- final Class<? extends SubsequentAddressFamily> safi, final PeerSpecificParserConstraint constraint) {
- if (MultiPathSupportUtil.isTableTypeSupported(constraint, new BgpTableTypeImpl(afi, safi))) {
- return PathIdUtil.readPathId(nlri);
- }
- return null;
- }
-
@Override
public final void parseNlri(@Nonnull final ByteBuf nlri, @Nonnull final MpUnreachNlriBuilder builder,
- @Nullable final PeerSpecificParserConstraint constraint)
- throws BGPParsingException {
+ @Nullable final PeerSpecificParserConstraint constraint) throws BGPParsingException {
if (!nlri.isReadable()) {
return;
}
).build()
);
}
+
+ @Nullable
+ protected static PathId readPathId(@Nonnull final ByteBuf nlri, final Class<? extends AddressFamily> afi,
+ final Class<? extends SubsequentAddressFamily> safi, final PeerSpecificParserConstraint constraint) {
+ if (MultiPathSupportUtil.isTableTypeSupported(constraint, new BgpTableTypeImpl(afi, safi))) {
+ return PathIdUtil.readPathId(nlri);
+ }
+ return null;
+ }
}