Search in sources :

Example 1 with Aigp

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.Aigp 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());
}
Also used : BGPExtensionProviderContext(org.opendaylight.protocol.bgp.parser.spi.BGPExtensionProviderContext) ServiceLoaderBGPExtensionProviderContext(org.opendaylight.protocol.bgp.parser.spi.pojo.ServiceLoaderBGPExtensionProviderContext) Attributes(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.Attributes) ByteBuf(io.netty.buffer.ByteBuf) AigpTlv(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.aigp.AigpTlv) Aigp(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.Aigp) Test(org.junit.Test)

Example 2 with Aigp

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

the class AigpAttributeParser method serializeAttribute.

@Override
public void serializeAttribute(final DataObject attribute, final ByteBuf byteAggregator) {
    Preconditions.checkArgument(attribute instanceof Attributes, "Attribute parameter is not a PathAttribute object.");
    final Aigp aigpAttribute = ((Attributes) attribute).getAigp();
    if (aigpAttribute == null) {
        return;
    }
    AttributeUtil.formatAttribute(AttributeUtil.OPTIONAL, TYPE, serializeAigpTLV(aigpAttribute), byteAggregator);
}
Also used : Attributes(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.Attributes) Aigp(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.Aigp)

Example 3 with Aigp

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

the class PathAttributeParserTest method testSerializingAigpAttribute.

@Test
public void testSerializingAigpAttribute() throws BGPDocumentedException, BGPParsingException {
    final byte[] value = new byte[] { 1, 0, 11, 0, 0, 0, 0, 0, 0, 0, 8 };
    final ByteBuf inputData = Unpooled.buffer();
    final ByteBuf testBuffer = Unpooled.buffer();
    AttributeUtil.formatAttribute(AttributeUtil.OPTIONAL, AigpAttributeParser.TYPE, Unpooled.copiedBuffer(value), inputData);
    final BGPExtensionProviderContext providerContext = ServiceLoaderBGPExtensionProviderContext.getSingletonInstance();
    final Attributes pathAttributes = providerContext.getAttributeRegistry().parseAttributes(inputData, null);
    final Aigp aigp = pathAttributes.getAigp();
    final AttributesBuilder pathAttributesBuilder = new AttributesBuilder();
    pathAttributesBuilder.setAigp(aigp);
    final AigpAttributeParser parser = new AigpAttributeParser();
    parser.serializeAttribute(pathAttributesBuilder.build(), testBuffer);
    final byte[] unparserData = inputData.copy(0, inputData.writerIndex()).array();
    final byte[] serializedData = testBuffer.copy(0, inputData.writerIndex()).array();
    assertTrue("Buffers should be the same.", Arrays.equals(unparserData, serializedData));
}
Also used : BGPExtensionProviderContext(org.opendaylight.protocol.bgp.parser.spi.BGPExtensionProviderContext) ServiceLoaderBGPExtensionProviderContext(org.opendaylight.protocol.bgp.parser.spi.pojo.ServiceLoaderBGPExtensionProviderContext) Attributes(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.Attributes) AigpAttributeParser(org.opendaylight.protocol.bgp.parser.impl.message.update.AigpAttributeParser) ByteBuf(io.netty.buffer.ByteBuf) AttributesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.AttributesBuilder) Aigp(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.Aigp) Test(org.junit.Test)

Example 4 with Aigp

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.Aigp 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)

Aggregations

ByteBuf (io.netty.buffer.ByteBuf)3 Attributes (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.Attributes)3 Aigp (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.Aigp)3 Test (org.junit.Test)2 BGPExtensionProviderContext (org.opendaylight.protocol.bgp.parser.spi.BGPExtensionProviderContext)2 ServiceLoaderBGPExtensionProviderContext (org.opendaylight.protocol.bgp.parser.spi.pojo.ServiceLoaderBGPExtensionProviderContext)2 AigpTlv (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.aigp.AigpTlv)2 AigpAttributeParser (org.opendaylight.protocol.bgp.parser.impl.message.update.AigpAttributeParser)1 AttributesBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.AttributesBuilder)1