use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.ObjectHeader in project bgpcep by opendaylight.
the class PCCEndPointIpv4ObjectParser method parseObject.
@Override
public Object parseObject(final ObjectHeader header, final ByteBuf bytes) throws PCEPDeserializerException {
checkArgument(bytes != null && bytes.isReadable(), "Array of bytes is mandatory. Can't be null or empty.");
final EndpointsObjBuilder builder = new EndpointsObjBuilder();
if (bytes.readableBytes() != Ipv4Util.IP4_LENGTH * 2) {
throw new PCEPDeserializerException("Wrong length of array of bytes.");
}
builder.setIgnore(header.getIgnore());
builder.setProcessingRule(header.getProcessingRule());
final Ipv4Builder b = new Ipv4Builder();
b.setSourceIpv4Address(Ipv4Util.addressForByteBuf(bytes));
b.setDestinationIpv4Address(Ipv4Util.addressForByteBuf(bytes));
builder.setAddressFamily(new Ipv4CaseBuilder().setIpv4(b.build()).build());
return builder.build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.ObjectHeader in project bgpcep by opendaylight.
the class AbstractMessageParser method parseObjects.
private Queue<Object> parseObjects(final ByteBuf bytes) throws PCEPDeserializerException {
final Queue<Object> objs = new ArrayDeque<>();
while (bytes.isReadable()) {
if (bytes.readableBytes() < COMMON_OBJECT_HEADER_LENGTH) {
throw new PCEPDeserializerException("Too few bytes in passed array. Passed: " + bytes.readableBytes() + " Expected: >= " + COMMON_OBJECT_HEADER_LENGTH + ".");
}
final int objClass = bytes.readUnsignedByte();
final byte flagsByte = bytes.readByte();
final BitArray flags = BitArray.valueOf(flagsByte);
final int objType = UnsignedBytes.toInt(ByteArray.copyBitsRange(flagsByte, OT_SF_OFFSET, OT_SF_LENGTH));
final int objLength = bytes.readUnsignedShort();
if (bytes.readableBytes() < objLength - COMMON_OBJECT_HEADER_LENGTH) {
throw new PCEPDeserializerException("Too few bytes in passed array. Passed: " + bytes.readableBytes() + " Expected: >= " + objLength + ".");
}
// copy bytes for deeper parsing
final ByteBuf bytesToPass = bytes.readSlice(objLength - COMMON_OBJECT_HEADER_LENGTH);
final ObjectHeader header = new ObjectHeaderImpl(flags.get(PROCESSED), flags.get(IGNORED));
if (VendorInformationUtil.isVendorInformationObject(objClass, objType)) {
final EnterpriseNumber enterpriseNumber = new EnterpriseNumber(ByteBufUtils.readUint32(bytesToPass));
this.registry.parseVendorInformationObject(enterpriseNumber, header, bytesToPass).ifPresent(objs::add);
} else {
// parseObject is required to return null for P=0 errored objects
final Object o = this.registry.parseObject(objClass, objType, header, bytesToPass);
if (o != null) {
objs.add(o);
}
}
}
return objs;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.ObjectHeader in project bgpcep by opendaylight.
the class PCCEndPointIpv4ObjectParserTest method testNullBytes.
@Test(expected = IllegalArgumentException.class)
public void testNullBytes() throws PCEPDeserializerException {
final ObjectHeader header = new ObjectHeaderImpl(false, false);
final ByteBuf bytes = null;
new PCCEndPointIpv4ObjectParser().parseObject(header, bytes);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.ObjectHeader in project bgpcep by opendaylight.
the class PCCEndPointIpv4ObjectParserTest method testEmptyBytes.
@Test(expected = IllegalArgumentException.class)
public void testEmptyBytes() throws PCEPDeserializerException {
final ObjectHeader header = new ObjectHeaderImpl(false, false);
final ByteBuf bytes = Unpooled.buffer();
new PCCEndPointIpv4ObjectParser().parseObject(header, bytes);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.ObjectHeader in project bgpcep by opendaylight.
the class Stateful07SrpObjectParser method parseObject.
@Override
public Srp parseObject(final ObjectHeader header, final ByteBuf bytes) throws PCEPDeserializerException {
Preconditions.checkArgument(bytes != null && bytes.isReadable(), "Array of bytes is mandatory. Can't be null or empty.");
if (bytes.readableBytes() < MIN_SIZE) {
throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + bytes.readableBytes() + "; Expected: >=" + MIN_SIZE + ".");
}
final SrpBuilder builder = new SrpBuilder();
builder.setIgnore(header.isIgnore());
builder.setProcessingRule(header.isProcessingRule());
parseFlags(builder, bytes);
builder.setOperationId(new SrpIdNumber(bytes.readUnsignedInt()));
final TlvsBuilder tlvsBuilder = new TlvsBuilder();
parseTlvs(tlvsBuilder, bytes.slice());
builder.setTlvs(tlvsBuilder.build());
return builder.build();
}
Aggregations