use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.aigp.AigpTlv in project bgpcep by opendaylight.
the class PathAttributeParserTest method testParsingAigpAttributeWithCorrectTLV.
@Test
public void testParsingAigpAttributeWithCorrectTLV() throws BGPDocumentedException, BGPParsingException {
final byte[] value = new byte[] { 1, 0, 11, 0, 0, 0, 0, 0, 0, 0, 8 };
final ByteBuf buffer = Unpooled.buffer();
AttributeUtil.formatAttribute(AttributeUtil.OPTIONAL, AigpAttributeParser.TYPE, Unpooled.copiedBuffer(value), buffer);
final BGPExtensionProviderContext providerContext = ServiceLoaderBGPExtensionProviderContext.getSingletonInstance();
final Attributes pathAttributes = providerContext.getAttributeRegistry().parseAttributes(buffer, null);
final Aigp aigp = pathAttributes.getAigp();
final AigpTlv tlv = aigp.getAigpTlv();
assertNotNull("Tlv should not be null.", tlv);
assertEquals("Aigp tlv should have metric with value 8.", 8, tlv.getMetric().getValue().intValue());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.aigp.AigpTlv in project bgpcep by opendaylight.
the class AigpAttributeParser method serializeAigpTLV.
/**
* Transform AIGP attribute data from instance of Aigp class into byte buffer representation.
*
* @param aigp
* instance of Aigp class
* @return
* byte buffer representation or empty buffer if AIGP TLV is null
*/
private static ByteBuf serializeAigpTLV(final Aigp aigp) {
final AigpTlv tlv = aigp.getAigpTlv();
if (tlv == null) {
return Unpooled.EMPTY_BUFFER;
}
final ByteBuf value = Unpooled.buffer(AIGP_TLV_SIZE);
value.writeByte(AIGP_TLV_TYPE);
value.writeShort(AIGP_TLV_SIZE);
value.writeLong(tlv.getMetric().getValue().longValue());
return value;
}
Aggregations