use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev171207.Tlv in project bgpcep by opendaylight.
the class StatType009TlvHandler method serializeTlv.
@Override
public void serializeTlv(final Tlv tlv, final ByteBuf output) {
Preconditions.checkArgument(tlv instanceof PerAfiSafiAdjRibInTlv, "PerAfiSafiAdjRibInTlv is mandatory.");
final ByteBuf buffer = Unpooled.buffer();
ByteBufWriteUtil.writeUnsignedShort(this.afiRegistry.numberForClass(((PerAfiSafiAdjRibInTlv) tlv).getAfi()), buffer);
ByteBufWriteUtil.writeUnsignedByte(this.safiRegistry.numberForClass(((PerAfiSafiAdjRibInTlv) tlv).getSafi()).shortValue(), buffer);
ByteBufWriteUtil.writeUnsignedLong(((PerAfiSafiAdjRibInTlv) tlv).getCount().getValue(), buffer);
TlvUtil.formatTlv(TYPE, buffer, output);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev171207.Tlv in project bgpcep by opendaylight.
the class StatType010TlvHandler method serializeTlv.
@Override
public void serializeTlv(final Tlv tlv, final ByteBuf output) {
Preconditions.checkArgument(tlv instanceof PerAfiSafiLocRibTlv, "PerAfiSafiLocRibInTlv is mandatory.");
final ByteBuf buffer = Unpooled.buffer();
writeUnsignedShort(this.afiRegistry.numberForClass(((PerAfiSafiLocRibTlv) tlv).getAfi()), buffer);
writeUnsignedByte(this.safiRegistry.numberForClass(((PerAfiSafiLocRibTlv) tlv).getSafi()).shortValue(), buffer);
writeUnsignedLong(((PerAfiSafiLocRibTlv) tlv).getCount().getValue(), buffer);
TlvUtil.formatTlv(TYPE, buffer, output);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev171207.Tlv in project bgpcep by opendaylight.
the class SrObjectParserTest method testOpenObjectWithSpcTlv.
@Test
public void testOpenObjectWithSpcTlv() throws PCEPDeserializerException {
final PcepOpenObjectWithSpcTlvParser parser = new PcepOpenObjectWithSpcTlvParser(this.tlvRegistry, this.viTlvRegistry);
final OpenBuilder builder = new OpenBuilder();
builder.setProcessingRule(false);
builder.setIgnore(false);
builder.setVersion(new ProtocolVersion((short) 1));
builder.setKeepalive((short) 30);
builder.setDeadTimer((short) 120);
builder.setSessionId((short) 1);
final Tlvs1 tlv = new Tlvs1Builder().setSrPceCapability(new SrPceCapabilityBuilder().setMsd((short) 1).build()).build();
builder.setTlvs(new TlvsBuilder().addAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev171025.Tlvs1.class, new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev171025.Tlvs1Builder().build()).addAugmentation(Tlvs1.class, tlv).addAugmentation(Tlvs3.class, new Tlvs3Builder().build()).build());
final ByteBuf result = Unpooled.wrappedBuffer(openObjectBytes);
assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
final ByteBuf buffer = Unpooled.buffer();
parser.serializeObject(builder.build(), buffer);
parser.serializeTlvs(null, Unpooled.EMPTY_BUFFER);
parser.serializeTlvs(new TlvsBuilder().build(), Unpooled.EMPTY_BUFFER);
assertArrayEquals(openObjectBytes, ByteArray.getAllBytes(buffer));
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev171207.Tlv 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.bmp.message.rev171207.Tlv 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);
}
Aggregations