Search in sources :

Example 1 with UnrecognizedAttributes

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.UnrecognizedAttributes 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 List<UnrecognizedAttributes> unrecognizedAttrs = new ArrayList<>();
    final UnrecognizedAttributes unrecognizedAttribute1 = new UnrecognizedAttributesBuilder().setPartial(true).setTransitive(true).setType((short) 101).setValue(unrecognizedValue1).build();
    unrecognizedAttrs.add(unrecognizedAttribute1);
    final UnrecognizedAttributes unrecognizedAttribute2 = new UnrecognizedAttributesBuilder().setPartial(true).setTransitive(true).setType((short) 102).setValue(unrecognizedValue2).build();
    unrecognizedAttrs.add(unrecognizedAttribute2);
    final Attributes attrs = new AttributesBuilder().setUnrecognizedAttributes(unrecognizedAttrs).build();
    final ByteBuf buffer = Unpooled.buffer();
    ServiceLoaderBGPExtensionProviderContext.getSingletonInstance().getAttributeRegistry().serializeAttribute(attrs, buffer);
    assertArrayEquals(unrecognizedBytes, ByteArray.readAllBytes(buffer));
}
Also used : ArrayList(java.util.ArrayList) UnrecognizedAttributes(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.UnrecognizedAttributes) Attributes(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.Attributes) UnrecognizedAttributesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.UnrecognizedAttributesBuilder) ByteBuf(io.netty.buffer.ByteBuf) UnrecognizedAttributesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.UnrecognizedAttributesBuilder) AttributesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.AttributesBuilder) UnrecognizedAttributes(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.UnrecognizedAttributes) Test(org.junit.Test)

Example 2 with UnrecognizedAttributes

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

the class UnrecognizedAttributesTest method testUnrecognizedAttributes.

@Test
public void testUnrecognizedAttributes() throws BGPDocumentedException, BGPParsingException {
    final byte[] attributeBytes = { (byte) 0xe0, 0x00, 0x05, 0x01, 0x02, 0x03, 0x04, 0x05 };
    final List<UnrecognizedAttributes> unrecogAttribs = simpleAttrReg.parseAttributes(Unpooled.wrappedBuffer(attributeBytes), null).getUnrecognizedAttributes();
    assertEquals(UNRECOGNIZED_ATTRIBUTE_COUNT, unrecogAttribs.size());
    final UnrecognizedAttributes unrecogAttrib = unrecogAttribs.get(FIRST_ATTRIBUTE);
    final UnrecognizedAttributesKey expectedAttribKey = new UnrecognizedAttributesKey(unrecogAttrib.getType());
    assertTrue(unrecogAttrib.isPartial());
    assertTrue(unrecogAttrib.isTransitive());
    assertArrayEquals(ByteArray.cutBytes(attributeBytes, NON_VALUE_BYTES), unrecogAttrib.getValue());
    assertEquals(NON_EXISTENT_TYPE, unrecogAttrib.getType().shortValue());
    assertEquals(expectedAttribKey, unrecogAttrib.getKey());
}
Also used : UnrecognizedAttributesKey(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.UnrecognizedAttributesKey) UnrecognizedAttributes(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.UnrecognizedAttributes) Test(org.junit.Test)

Example 3 with UnrecognizedAttributes

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

the class NonTransitiveAttributesFilterHandler method filterAttributes.

private Attributes filterAttributes(final Attributes attributes) {
    final AttributesBuilder builder = new AttributesBuilder();
    builder.setCNextHop(attributes.getCNextHop());
    builder.setOrigin(attributes.getOrigin());
    builder.setAsPath(attributes.getAsPath());
    builder.setCommunities(attributes.getCommunities());
    final List<UnrecognizedAttributes> oldAtt = attributes.getUnrecognizedAttributes();
    if (oldAtt != null) {
        builder.setUnrecognizedAttributes(attributes.getUnrecognizedAttributes().stream().filter(UnrecognizedAttributes::isTransitive).collect(Collectors.toList()));
    }
    final List<ExtendedCommunities> oldExt = attributes.getExtendedCommunities();
    if (oldExt != null) {
        builder.setExtendedCommunities(oldExt.stream().filter(ExtendedCommunity::isTransitive).collect(Collectors.toList()));
    }
    return builder.build();
}
Also used : ExtendedCommunities(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.ExtendedCommunities) ExtendedCommunity(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.ExtendedCommunity) AttributesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.AttributesBuilder) UnrecognizedAttributes(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.UnrecognizedAttributes)

Example 4 with UnrecognizedAttributes

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.UnrecognizedAttributes 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 UnrecognizedAttributes unrecognizedAttribute = new UnrecognizedAttributesBuilder().setKey(new UnrecognizedAttributesKey((short) type)).setPartial(flags.get(PARTIAL_BIT)).setTransitive(flags.get(TRANSITIVE_BIT)).setType((short) type).setValue(ByteArray.readBytes(buffer, len)).build();
    this.unrecognizedAttributes.add(unrecognizedAttribute);
    LOG.debug("Unrecognized attribute were parsed: {}", unrecognizedAttribute);
}
Also used : BGPDocumentedException(org.opendaylight.protocol.bgp.parser.BGPDocumentedException) UnrecognizedAttributesKey(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.UnrecognizedAttributesKey) UnrecognizedAttributesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.UnrecognizedAttributesBuilder) UnrecognizedAttributes(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.UnrecognizedAttributes)

Example 5 with UnrecognizedAttributes

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

the class UnrecognizedAttributesSerializer method serializeAttribute.

@Override
public void serializeAttribute(final DataObject attributes, final ByteBuf byteAggregator) {
    Preconditions.checkArgument(attributes instanceof Attributes, "Attributes parameter is not a PathAttribute object.");
    final List<UnrecognizedAttributes> unrecognizedAttrs = ((Attributes) attributes).getUnrecognizedAttributes();
    if (unrecognizedAttrs == null) {
        return;
    }
    for (final UnrecognizedAttributes unrecognizedAttr : unrecognizedAttrs) {
        LOG.trace("Serializing unrecognized attribute of type {}", unrecognizedAttr.getType());
        int flags = AttributeUtil.OPTIONAL;
        if (unrecognizedAttr.isPartial()) {
            flags |= AttributeUtil.PARTIAL;
        }
        if (unrecognizedAttr.isTransitive()) {
            flags |= AttributeUtil.TRANSITIVE;
        }
        AttributeUtil.formatAttribute(flags, unrecognizedAttr.getType(), Unpooled.wrappedBuffer(unrecognizedAttr.getValue()), byteAggregator);
    }
}
Also used : UnrecognizedAttributes(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.UnrecognizedAttributes) Attributes(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.Attributes) UnrecognizedAttributes(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.UnrecognizedAttributes)

Aggregations

UnrecognizedAttributes (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.UnrecognizedAttributes)5 Test (org.junit.Test)2 Attributes (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.Attributes)2 AttributesBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.AttributesBuilder)2 UnrecognizedAttributesBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.UnrecognizedAttributesBuilder)2 UnrecognizedAttributesKey (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.UnrecognizedAttributesKey)2 ByteBuf (io.netty.buffer.ByteBuf)1 ArrayList (java.util.ArrayList)1 BGPDocumentedException (org.opendaylight.protocol.bgp.parser.BGPDocumentedException)1 ExtendedCommunities (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.ExtendedCommunities)1 ExtendedCommunity (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.ExtendedCommunity)1