import com.google.common.base.Preconditions;
import io.netty.buffer.ByteBuf;
+import java.util.ArrayList;
import java.util.LinkedHashMap;
+import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.TreeMap;
import org.opendaylight.protocol.concepts.AbstractRegistration;
import org.opendaylight.protocol.concepts.HandlerRegistry;
import org.opendaylight.protocol.util.BitArray;
+import org.opendaylight.protocol.util.ByteArray;
import org.opendaylight.protocol.util.Values;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.update.PathAttributes;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.update.PathAttributesBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.Attributes;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.AttributesBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.attributes.UnrecognizedAttributes;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.attributes.UnrecognizedAttributesBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.attributes.UnrecognizedAttributesKey;
import org.opendaylight.yangtools.yang.binding.DataContainer;
import org.opendaylight.yangtools.yang.binding.DataObject;
import org.slf4j.Logger;
private static final Logger LOG = LoggerFactory.getLogger(SimpleAttributeRegistry.class);
private static final int OPTIONAL_BIT = 0;
private static final int TRANSITIVE_BIT = 1;
- @SuppressWarnings("unused")
private static final int PARTIAL_BIT = 2;
private static final int EXTENDED_LENGTH_BIT = 3;
private final HandlerRegistry<DataContainer, AttributeParser, AttributeSerializer> handlers = new HandlerRegistry<>();
private final Map<AbstractRegistration, AttributeSerializer> serializers = new LinkedHashMap<>();
private final AtomicReference<Iterable<AttributeSerializer>> roSerializers =
new AtomicReference<Iterable<AttributeSerializer>>(this.serializers.values());
+ private final List<UnrecognizedAttributes> unrecognizedAttributes = new ArrayList<>();
+
AutoCloseable registerAttributeParser(final int attributeType, final AttributeParser parser) {
Preconditions.checkArgument(attributeType >= 0 && attributeType <= Values.UNSIGNED_BYTE_MAX_VALUE);
if (!flags.get(OPTIONAL_BIT)) {
throw new BGPDocumentedException("Well known attribute not recognized.", BGPError.WELL_KNOWN_ATTR_NOT_RECOGNIZED);
}
- if (flags.get(TRANSITIVE_BIT)) {
- // FIXME: transitive attributes need to be preserved
- LOG.warn("Losing unrecognized transitive attribute {}. Some data might be missing from the output.", type);
- } else {
- LOG.warn("Ignoring unrecognized attribute type {}. Some data might be missing from the output.", type);
- }
+ 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);
} else {
attributes.put(type, new RawAttribute(parser, buffer.readSlice(len)));
}
}
@Override
- public PathAttributes parseAttributes(final ByteBuf buffer) throws BGPDocumentedException, BGPParsingException {
+ public Attributes parseAttributes(final ByteBuf buffer) throws BGPDocumentedException, BGPParsingException {
final Map<Integer, RawAttribute> attributes = new TreeMap<>();
while (buffer.isReadable()) {
addAttribute(buffer, attributes);
* TreeMap guarantees that we will be invoking the parser in the order
* of increasing attribute type.
*/
- final PathAttributesBuilder builder = new PathAttributesBuilder();
+ final AttributesBuilder builder = new AttributesBuilder();
for (final Entry<Integer, RawAttribute> e : attributes.entrySet()) {
LOG.debug("Parsing attribute type {}", e.getKey());
final RawAttribute a = e.getValue();
a.parser.parseAttribute(a.buffer, builder);
}
+ builder.setUnrecognizedAttributes(this.unrecognizedAttributes);
return builder.build();
}