Search in sources :

Example 1 with UnrecognizedAttributesKey

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

the class UnrecognizedAttributesSerializer method serializeAttribute.

@Override
public void serializeAttribute(final Attributes attributes, final ByteBuf byteAggregator) {
    final Map<UnrecognizedAttributesKey, UnrecognizedAttributes> unrecognizedAttrs = attributes.getUnrecognizedAttributes();
    if (unrecognizedAttrs == null) {
        return;
    }
    for (final UnrecognizedAttributes unrecognizedAttr : unrecognizedAttrs.values()) {
        LOG.trace("Serializing unrecognized attribute of type {}", unrecognizedAttr.getType());
        int flags = AttributeUtil.OPTIONAL;
        if (unrecognizedAttr.getPartial()) {
            flags |= AttributeUtil.PARTIAL;
        }
        if (unrecognizedAttr.getTransitive()) {
            flags |= AttributeUtil.TRANSITIVE;
        }
        AttributeUtil.formatAttribute(flags, unrecognizedAttr.getType().toJava(), Unpooled.wrappedBuffer(unrecognizedAttr.getValue()), byteAggregator);
    }
}
Also used : UnrecognizedAttributesKey(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.attributes.UnrecognizedAttributesKey) UnrecognizedAttributes(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.attributes.UnrecognizedAttributes)

Example 2 with UnrecognizedAttributesKey

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.attributes.UnrecognizedAttributesKey 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 Map<UnrecognizedAttributesKey, UnrecognizedAttributes> unrecogAttribs = SIMPLE_ATTR_REG.parseAttributes(Unpooled.wrappedBuffer(attributeBytes), null).getAttributes().getUnrecognizedAttributes();
    assertEquals(UNRECOGNIZED_ATTRIBUTE_COUNT, unrecogAttribs.size());
    final UnrecognizedAttributes unrecogAttrib = unrecogAttribs.values().iterator().next();
    final UnrecognizedAttributesKey expectedAttribKey = new UnrecognizedAttributesKey(unrecogAttrib.getType());
    assertTrue(unrecogAttrib.getPartial());
    assertTrue(unrecogAttrib.getTransitive());
    assertArrayEquals(ByteArray.cutBytes(attributeBytes, NON_VALUE_BYTES), unrecogAttrib.getValue());
    assertEquals(NON_EXISTENT_TYPE, unrecogAttrib.getType().shortValue());
    assertEquals(expectedAttribKey, unrecogAttrib.key());
}
Also used : UnrecognizedAttributesKey(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.attributes.UnrecognizedAttributesKey) UnrecognizedAttributes(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.attributes.UnrecognizedAttributes) Test(org.junit.Test)

Example 3 with UnrecognizedAttributesKey

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

Example 4 with UnrecognizedAttributesKey

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

the class NonTransitiveAttributesFilterHandler method filterAttributes.

private static Attributes filterAttributes(final Attributes attributes) {
    final AttributesBuilder builder = new AttributesBuilder().setCNextHop(attributes.getCNextHop()).setOrigin(attributes.getOrigin()).setAsPath(attributes.getAsPath()).setCommunities(attributes.getCommunities());
    final Map<UnrecognizedAttributesKey, UnrecognizedAttributes> oldAtt = attributes.getUnrecognizedAttributes();
    if (oldAtt != null) {
        // TODO: consider using Maps.filterValues(attributes.getUnrecognizedAttributes(),
        // UnrecognizedAttributes::isTransitive)) ?
        builder.setUnrecognizedAttributes(attributes.getUnrecognizedAttributes().values().stream().filter(UnrecognizedAttributes::getTransitive).collect(ImmutableMap.toImmutableMap(UnrecognizedAttributes::key, Function.identity())));
    }
    final List<ExtendedCommunities> oldExt = attributes.getExtendedCommunities();
    if (oldExt != null) {
        builder.setExtendedCommunities(oldExt.stream().filter(ExtendedCommunity::getTransitive).collect(Collectors.toList()));
    }
    return builder.build();
}
Also used : UnrecognizedAttributesKey(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.attributes.UnrecognizedAttributesKey) ExtendedCommunities(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.attributes.ExtendedCommunities) ExtendedCommunity(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.ExtendedCommunity) 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)

Aggregations

UnrecognizedAttributes (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.attributes.UnrecognizedAttributes)4 UnrecognizedAttributesKey (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.attributes.UnrecognizedAttributesKey)4 Test (org.junit.Test)1 BGPDocumentedException (org.opendaylight.protocol.bgp.parser.BGPDocumentedException)1 AttributesBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.AttributesBuilder)1 ExtendedCommunities (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.attributes.ExtendedCommunities)1 UnrecognizedAttributesBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.attributes.UnrecognizedAttributesBuilder)1 ExtendedCommunity (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.ExtendedCommunity)1 Uint8 (org.opendaylight.yangtools.yang.common.Uint8)1