Search in sources :

Example 1 with UnrecognizedAttributesBuilder

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

the class UnrecognizedAttributesSerializerTest method testUnrecognizedAttributesSerializer.

@Test
public void testUnrecognizedAttributesSerializer() {
    final byte[] unrecognizedValue1 = { (byte) 0xd3, 0x5d, 0x35, (byte) 0xd3, 0x5d, 0x35, (byte) 0xd3, 0x5d, 0x35, (byte) 0xd3, 0x5d, 0x35 };
    final byte[] unrecognizedValue2 = { (byte) 0xd3, 0x5d, 0x35, (byte) 0xd3, 0x5d, 0x35, (byte) 0xd7, 0x5d, 0x75, (byte) 0xd7, 0x5d, 0x75 };
    final byte[] unrecognizedBytes = { (byte) 0xe0, 0x65, 0x0c, (byte) 0xd3, 0x5d, 0x35, (byte) 0xd3, 0x5d, 0x35, (byte) 0xd3, 0x5d, 0x35, (byte) 0xd3, 0x5d, 0x35, (byte) 0xe0, 0x66, 0x0c, (byte) 0xd3, 0x5d, 0x35, (byte) 0xd3, 0x5d, 0x35, (byte) 0xd7, 0x5d, 0x75, (byte) 0xd7, 0x5d, 0x75 };
    final UnrecognizedAttributes unrecognizedAttribute1 = new UnrecognizedAttributesBuilder().setPartial(true).setTransitive(true).setType(Uint8.valueOf(101)).setValue(unrecognizedValue1).build();
    final UnrecognizedAttributes unrecognizedAttribute2 = new UnrecognizedAttributesBuilder().setPartial(true).setTransitive(true).setType(Uint8.valueOf(102)).setValue(unrecognizedValue2).build();
    final Attributes attrs = new AttributesBuilder().setUnrecognizedAttributes(ImmutableMap.of(unrecognizedAttribute1.key(), unrecognizedAttribute1, unrecognizedAttribute2.key(), unrecognizedAttribute2)).build();
    final ByteBuf buffer = Unpooled.buffer();
    ServiceLoader.load(BGPExtensionConsumerContext.class).findFirst().orElseThrow().getAttributeRegistry().serializeAttribute(attrs, buffer);
    assertArrayEquals(unrecognizedBytes, ByteArray.readAllBytes(buffer));
}
Also used : Attributes(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.Attributes) UnrecognizedAttributes(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.attributes.UnrecognizedAttributes) UnrecognizedAttributesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.attributes.UnrecognizedAttributesBuilder) ByteBuf(io.netty.buffer.ByteBuf) UnrecognizedAttributesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.attributes.UnrecognizedAttributesBuilder) AttributesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.AttributesBuilder) UnrecognizedAttributes(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.attributes.UnrecognizedAttributes) Test(org.junit.Test)

Example 2 with UnrecognizedAttributesBuilder

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

the class SimpleAttributeRegistry method processUnrecognized.

private void processUnrecognized(final BitArray flags, final int type, final ByteBuf buffer, final int len) throws BGPDocumentedException {
    if (!flags.get(OPTIONAL_BIT)) {
        throw new BGPDocumentedException("Well known attribute not recognized.", BGPError.WELL_KNOWN_ATTR_NOT_RECOGNIZED);
    }
    final Uint8 typeVal = Uint8.valueOf(type);
    final UnrecognizedAttributes unrecognizedAttribute = new UnrecognizedAttributesBuilder().withKey(new UnrecognizedAttributesKey(typeVal)).setPartial(flags.get(PARTIAL_BIT)).setTransitive(flags.get(TRANSITIVE_BIT)).setType(typeVal).setValue(ByteArray.readBytes(buffer, len)).build();
    this.unrecognizedAttributes.add(unrecognizedAttribute);
    LOG.debug("Unrecognized attribute were parsed: {}", unrecognizedAttribute);
}
Also used : Uint8(org.opendaylight.yangtools.yang.common.Uint8) BGPDocumentedException(org.opendaylight.protocol.bgp.parser.BGPDocumentedException) UnrecognizedAttributesKey(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.attributes.UnrecognizedAttributesKey) UnrecognizedAttributesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.attributes.UnrecognizedAttributesBuilder) UnrecognizedAttributes(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.attributes.UnrecognizedAttributes)

Aggregations

UnrecognizedAttributes (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.attributes.UnrecognizedAttributes)2 UnrecognizedAttributesBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.attributes.UnrecognizedAttributesBuilder)2 ByteBuf (io.netty.buffer.ByteBuf)1 Test (org.junit.Test)1 BGPDocumentedException (org.opendaylight.protocol.bgp.parser.BGPDocumentedException)1 Attributes (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.Attributes)1 AttributesBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.AttributesBuilder)1 UnrecognizedAttributesKey (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.attributes.UnrecognizedAttributesKey)1 Uint8 (org.opendaylight.yangtools.yang.common.Uint8)1