use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.vendor.information.tlvs.VendorInformationTlv in project bgpcep by opendaylight.
the class PCEPObjectParserTest method testCloseObjectWithVendorInformationTlv.
@Test
public void testCloseObjectWithVendorInformationTlv() throws IOException, PCEPDeserializerException {
final byte[] closeBytes = { 0x0f, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x05, /* vendor-information TLV */
0x00, 0x07, 0x00, 0x08, /* enterprise number */
0x00, 0x00, 0x00, 0x00, /* enterprise specific information */
0x00, 0x00, 0x00, 0x05 };
final PCEPCloseObjectParser parser = new PCEPCloseObjectParser(this.tlvRegistry, this.viTlvRegistry);
final ByteBuf result = Unpooled.wrappedBuffer(closeBytes);
final TestEnterpriseSpecificInformation esInfo = new TestEnterpriseSpecificInformation(5);
final VendorInformationTlv viTlv = new VendorInformationTlvBuilder().setEnterpriseNumber(new EnterpriseNumber(0L)).setEnterpriseSpecificInformation(esInfo).build();
final CCloseBuilder builder = new CCloseBuilder();
builder.setProcessingRule(false);
builder.setIgnore(false);
builder.setReason((short) 5);
builder.setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.close.object.c.close.TlvsBuilder().setVendorInformationTlv(Lists.newArrayList(viTlv)).build());
assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
final ByteBuf buf = Unpooled.buffer();
parser.serializeObject(builder.build(), buf);
assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.vendor.information.tlvs.VendorInformationTlv in project bgpcep by opendaylight.
the class AbstractVendorInformationTlvParser method parseTlv.
@Override
public final VendorInformationTlv parseTlv(final ByteBuf buffer) throws PCEPDeserializerException {
if (buffer == null) {
return null;
}
final VendorInformationTlvBuilder viTlvBuider = new VendorInformationTlvBuilder();
viTlvBuider.setEnterpriseNumber(getEnterpriseNumber());
if (buffer.isReadable()) {
final EnterpriseSpecificInformation esInformation = parseEnterpriseSpecificInformation(buffer.slice());
if (esInformation != null) {
viTlvBuider.setEnterpriseSpecificInformation(esInformation);
}
}
return viTlvBuider.build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.vendor.information.tlvs.VendorInformationTlv in project bgpcep by opendaylight.
the class AbstractObjectWithTlvsParser method serializeVendorInformationTlvs.
protected final void serializeVendorInformationTlvs(final List<VendorInformationTlv> tlvs, final ByteBuf buffer) {
if (tlvs != null) {
for (final VendorInformationTlv tlv : tlvs) {
LOG.trace("Serializing VENDOR-INFORMATION TLV {}", tlv);
this.viTlvReg.serializeVendorInformationTlv(tlv, buffer);
LOG.trace("Serialized VENDOR-INFORMATION TLV : {}.", ByteBufUtil.hexDump(buffer));
}
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.vendor.information.tlvs.VendorInformationTlv in project bgpcep by opendaylight.
the class AbstractObjectWithTlvsParser method parseTlvs.
protected final void parseTlvs(final T builder, final ByteBuf bytes) throws PCEPDeserializerException {
Preconditions.checkArgument(bytes != null, "Array of bytes is mandatory. Can't be null.");
if (!bytes.isReadable()) {
return;
}
final List<VendorInformationTlv> viTlvs = Lists.newArrayList();
while (bytes.isReadable()) {
final int type = bytes.readUnsignedShort();
final int length = bytes.readUnsignedShort();
if (length > bytes.readableBytes()) {
throw new PCEPDeserializerException("Wrong length specified. Passed: " + length + "; Expected: <= " + bytes.readableBytes() + ".");
}
final ByteBuf tlvBytes = bytes.readSlice(length);
LOG.trace("Parsing PCEP TLV : {}", ByteBufUtil.hexDump(tlvBytes));
if (VendorInformationUtil.isVendorInformationTlv(type)) {
final EnterpriseNumber enterpriseNumber = new EnterpriseNumber(tlvBytes.readUnsignedInt());
final Optional<VendorInformationTlv> viTlv = this.viTlvReg.parseVendorInformationTlv(enterpriseNumber, tlvBytes);
if (viTlv.isPresent()) {
LOG.trace("Parsed VENDOR-INFORMATION TLV {}.", viTlv.get());
viTlvs.add(viTlv.get());
}
} else {
final Tlv tlv = this.tlvReg.parseTlv(type, tlvBytes);
if (tlv != null) {
LOG.trace("Parsed PCEP TLV {}.", tlv);
addTlv(builder, tlv);
}
}
bytes.skipBytes(TlvUtil.getPadding(TlvUtil.HEADER_SIZE + length, TlvUtil.PADDED_TO));
}
addVendorInformationTlvs(builder, viTlvs);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.vendor.information.tlvs.VendorInformationTlv in project bgpcep by opendaylight.
the class PCEPTlvParserTest method testVendorInformationTlv.
@Test
public void testVendorInformationTlv() throws PCEPDeserializerException {
final TestVendorInformationTlvParser parser = new TestVendorInformationTlvParser();
final TestEnterpriseSpecificInformation esInfo = new TestEnterpriseSpecificInformation(5);
final VendorInformationTlv viTlv = new VendorInformationTlvBuilder().setEnterpriseNumber(new EnterpriseNumber(0L)).setEnterpriseSpecificInformation(esInfo).build();
final VendorInformationTlv parsedTlv = parser.parseTlv(Unpooled.wrappedBuffer(ByteArray.cutBytes(VENDOR_INFO_BYTES, 8)));
assertEquals(viTlv, parsedTlv);
final ByteBuf buff = Unpooled.buffer(VENDOR_INFO_BYTES.length);
parser.serializeTlv(viTlv, buff);
assertArrayEquals(VENDOR_INFO_BYTES, ByteArray.getAllBytes(buff));
assertNull(parser.parseTlv(null));
}
Aggregations