use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.lsp.attributes.object.lsp.attributes.object.SubobjectContainer in project bgpcep by opendaylight.
the class RequiredAttributesObjectParser method localSerializeObject.
@Override
public void localSerializeObject(final RsvpTeObject teLspObject, final ByteBuf byteAggregator) {
Preconditions.checkArgument(teLspObject instanceof LspRequiredAttributesObject, "LspAttributesObject is mandatory.");
final LspRequiredAttributesObject lspAttributesObject = (LspRequiredAttributesObject) teLspObject;
final ByteBuf bufferAux = Unpooled.buffer();
int lenght = 0;
for (final SubobjectContainer subObject : lspAttributesObject.getLspAttributesObject().getSubobjectContainer()) {
final LspSubobject lspSubonject = subObject.getLspSubobject();
if (lspSubonject instanceof FlagsTlv) {
final ByteBuf flagTLVValue = Unpooled.buffer();
final List<FlagContainer> flagList = ((FlagsTlv) lspSubonject).getFlagContainer();
lenght = AttributesObjectParser.FLAG_TLV_SIZE * flagList.size();
AttributesObjectParser.serializeFlag(flagList, flagTLVValue);
AttributesObjectParser.serializeTLV(AttributesObjectParser.FLAG_TLV_TYPE, lenght, flagTLVValue, bufferAux);
lenght += AttributesObjectParser.TLV_HEADER_SIZE;
}
}
serializeAttributeHeader(lenght, CLASS_NUM, CTYPE, byteAggregator);
byteAggregator.writeBytes(bufferAux);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.lsp.attributes.object.lsp.attributes.object.SubobjectContainer 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.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.lsp.attributes.object.lsp.attributes.object.SubobjectContainer 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.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.lsp.attributes.object.lsp.attributes.object.SubobjectContainer in project bgpcep by opendaylight.
the class SimpleEROSubobjectRegistryTest method testSerializerRegistration.
@Test
public void testSerializerRegistration() {
assertNotNull(this.simpleEROSubobjectRegistry.registerSubobjectSerializer(LabelCase.class, this.rroSubobjectSerializer));
final SubobjectContainer container = new SubobjectContainerBuilder().setSubobjectType(new LabelCaseBuilder().build()).build();
final ByteBuf output = Unpooled.buffer();
this.simpleEROSubobjectRegistry.serializeSubobject(container, output);
assertEquals(1, output.readableBytes());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.lsp.attributes.object.lsp.attributes.object.SubobjectContainer in project bgpcep by opendaylight.
the class SimpleRROSubobjectRegistryTest method testUnrecognizedType.
@Test
public void testUnrecognizedType() throws RSVPParsingException {
final int wrongType = 99;
assertNull(this.simpleRROSubobjectRegistry.parseSubobject(wrongType, this.input));
final ByteBuf output = Unpooled.EMPTY_BUFFER;
final SubobjectContainer container = new SubobjectContainerBuilder().setSubobjectType(new LabelCaseBuilder().build()).build();
this.simpleRROSubobjectRegistry.serializeSubobject(container, output);
assertEquals(0, output.readableBytes());
}
Aggregations