Search in sources :

Example 1 with AigpTlv

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.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 Attributes pathAttributes = ctx.getAttributeRegistry().parseAttributes(buffer, null).getAttributes();
    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());
}
Also used : Attributes(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.Attributes) ByteBuf(io.netty.buffer.ByteBuf) AigpTlv(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.attributes.aigp.AigpTlv) Aigp(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.attributes.Aigp) Test(org.junit.Test)

Example 2 with AigpTlv

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.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;
}
Also used : AigpTlv(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.aigp.AigpTlv) ByteBuf(io.netty.buffer.ByteBuf)

Example 3 with AigpTlv

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.attributes.aigp.AigpTlv in project bgpcep by opendaylight.

the class AigpAttributeParser method parseAigpTLV.

/**
 * Reads data from buffer until reaches TLV of type AIGP TLV.
 *
 * @param buffer TLVs in ByteBuf format
 * @return instance of AigpTlv class or null if buffer contains unknown TLV type
 */
private static AigpTlv parseAigpTLV(final ByteBuf buffer) {
    final int tlvType = buffer.readByte();
    buffer.skipBytes(TLV_SIZE_IN_BYTES);
    if (tlvType != AIGP_TLV_TYPE) {
        LOG.warn("AIGP attribute contains unknown TLV type {}.", tlvType);
        return null;
    }
    return new AigpTlvBuilder().setMetric(new AccumulatedIgpMetric(ByteBufUtils.readUint64(buffer))).build();
}
Also used : AigpTlvBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.attributes.aigp.AigpTlvBuilder) AccumulatedIgpMetric(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.AccumulatedIgpMetric) PeerSpecificParserConstraint(org.opendaylight.protocol.bgp.parser.spi.PeerSpecificParserConstraint)

Aggregations

ByteBuf (io.netty.buffer.ByteBuf)2 Test (org.junit.Test)1 PeerSpecificParserConstraint (org.opendaylight.protocol.bgp.parser.spi.PeerSpecificParserConstraint)1 AigpTlv (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.aigp.AigpTlv)1 Attributes (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.Attributes)1 Aigp (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.attributes.Aigp)1 AigpTlv (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.attributes.aigp.AigpTlv)1 AigpTlvBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.attributes.aigp.AigpTlvBuilder)1 AccumulatedIgpMetric (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.AccumulatedIgpMetric)1