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