use of org.opendaylight.protocol.rsvp.parser.spi.RSVPParsingException in project bgpcep by opendaylight.
the class XROUnnumberedInterfaceSubobjectParser method parseSubobject.
@Override
public SubobjectContainer parseSubobject(final ByteBuf buffer, final boolean mandatory) throws RSVPParsingException {
Preconditions.checkArgument(buffer != null && buffer.isReadable(), "Array of bytes is mandatory. Can't be null or empty.");
if (buffer.readableBytes() != CONTENT_LENGTH) {
throw new RSVPParsingException("Wrong length of array of bytes. Passed: " + buffer.readableBytes() + "; " + "Expected: " + CONTENT_LENGTH + ".");
}
buffer.readerIndex(buffer.readerIndex() + RESERVED);
final SubobjectContainerBuilder builder = new SubobjectContainerBuilder();
builder.setMandatory(mandatory);
builder.setAttribute(ExcludeRouteSubobjects.Attribute.forValue(buffer.readUnsignedByte()));
builder.setSubobjectType(parseUnnumeredInterface(buffer));
return builder.build();
}
use of org.opendaylight.protocol.rsvp.parser.spi.RSVPParsingException in project bgpcep by opendaylight.
the class ProtectionCommonParser method parseCommonProtectionBodyType2.
protected static ProtectionSubobject parseCommonProtectionBodyType2(final ByteBuf byteBuf) throws RSVPParsingException {
if (byteBuf.readableBytes() != CONTENT_LENGTH_C2) {
throw new RSVPParsingException("Wrong length of array of bytes. Passed: " + byteBuf.readableBytes() + "; " + "Expected: " + CONTENT_LENGTH_C2 + ".");
}
final ProtectionSubobjectBuilder sub = new ProtectionSubobjectBuilder();
final BitArray protectionFlag = BitArray.valueOf(byteBuf.readByte());
sub.setSecondary(protectionFlag.get(SECONDARY));
sub.setProtecting(protectionFlag.get(PROTECTING));
sub.setNotification(protectionFlag.get(NOTIFICATION));
sub.setOperational(protectionFlag.get(OPERATIONAL));
final int lspFlags = byteBuf.readByte();
sub.setLspFlag(LspFlag.forValue(lspFlags)).build();
// Skip Reserved
byteBuf.skipBytes(ByteBufWriteUtil.ONE_BYTE_LENGTH);
final int linkFlags = byteBuf.readByte();
sub.setLinkFlags(LinkFlags.forValue(linkFlags));
final BitArray bitArray2 = BitArray.valueOf(byteBuf.readByte());
sub.setInPlace(bitArray2.get(IN_PLACE));
sub.setRequired(bitArray2.get(REQUIRED));
final int segFlags = byteBuf.readByte();
sub.setSegFlag(LspFlag.forValue(segFlags));
byteBuf.skipBytes(ByteBufWriteUtil.SHORT_BYTES_LENGTH);
return sub.build();
}
use of org.opendaylight.protocol.rsvp.parser.spi.RSVPParsingException in project bgpcep by opendaylight.
the class EROSubobjectListParser method parseList.
public List<SubobjectContainer> parseList(final ByteBuf buffer) throws RSVPParsingException {
// Explicit approval of empty ERO
Preconditions.checkArgument(buffer != null, "Array of bytes is mandatory. Can't be null.");
final List<SubobjectContainer> subs = new ArrayList<>();
while (buffer.isReadable()) {
final boolean loose = (buffer.getUnsignedByte(buffer.readerIndex()) & (1 << Values.FIRST_BIT_OFFSET)) != 0;
final int type = (buffer.readUnsignedByte() & Values.BYTE_MAX_VALUE_BYTES) & ~(1 << Values.FIRST_BIT_OFFSET);
final int length = buffer.readUnsignedByte() - HEADER_LENGTH;
if (length > buffer.readableBytes()) {
throw new RSVPParsingException("Wrong length specified. Passed: " + length + "; Expected: <= " + buffer.readableBytes());
}
LOG.debug("Attempt to parse subobject from bytes: {}", ByteBufUtil.hexDump(buffer));
final SubobjectContainer sub = this.subobjReg.parseSubobject(type, buffer.readSlice(length), loose);
if (sub == null) {
LOG.warn("Unknown subobject type: {}. Ignoring subobject.", type);
} else {
LOG.debug("Subobject was parsed. {}", sub);
subs.add(sub);
}
}
return subs;
}
use of org.opendaylight.protocol.rsvp.parser.spi.RSVPParsingException in project bgpcep by opendaylight.
the class XROSubobjectListParser method parseList.
public List<SubobjectContainer> parseList(final ByteBuf byteBuf) throws RSVPParsingException {
final List<SubobjectContainer> subs = new ArrayList<>();
while (byteBuf.isReadable()) {
final boolean mandatory = (byteBuf.getUnsignedByte(byteBuf.readerIndex()) & (1 << Values.FIRST_BIT_OFFSET)) != 0;
final int type = UnsignedBytes.checkedCast((byteBuf.readUnsignedByte() & Values.BYTE_MAX_VALUE_BYTES) & ~(1 << Values.FIRST_BIT_OFFSET));
final int length = byteBuf.readUnsignedByte() - HEADER_LENGHT;
if (length > byteBuf.readableBytes()) {
throw new RSVPParsingException("Wrong length specified. Passed: " + length + "; Expected: <= " + byteBuf.readableBytes());
}
LOG.debug("Attempt to parse subobject from bytes: {}", ByteBufUtil.hexDump(byteBuf));
final SubobjectContainer sub = this.subobjReg.parseSubobject(type, byteBuf.readSlice(length), mandatory);
if (sub == null) {
LOG.warn("Unknown subobject type: {}. Ignoring subobject.", type);
} else {
LOG.debug("Subobject was parsed. {}", sub);
subs.add(sub);
}
}
return subs;
}
use of org.opendaylight.protocol.rsvp.parser.spi.RSVPParsingException in project bgpcep by opendaylight.
the class EROIpv4PrefixSubobjectParser method parseSubobject.
@Override
public SubobjectContainer parseSubobject(final ByteBuf buffer, final boolean loose) throws RSVPParsingException {
Preconditions.checkArgument(buffer != null && buffer.isReadable(), "Array of bytes is mandatory. Can't be null or empty.");
final SubobjectContainerBuilder builder = new SubobjectContainerBuilder();
builder.setLoose(loose);
if (buffer.readableBytes() != CONTENT4_LENGTH) {
throw new RSVPParsingException("Wrong length of array of bytes. Passed: " + buffer.readableBytes() + ";");
}
final int length = buffer.getUnsignedByte(PREFIX4_F_OFFSET);
final IpPrefixBuilder prefix = new IpPrefixBuilder().setIpPrefix(new IpPrefix(Ipv4Util.prefixForBytes(ByteArray.readBytes(buffer, Ipv4Util.IP4_LENGTH), length)));
builder.setSubobjectType(new IpPrefixCaseBuilder().setIpPrefix(prefix.build()).build());
return builder.build();
}
Aggregations