2 * Copyright (c) 2016 Brocade Communications Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.protocol.bgp.parser.impl.message.update;
11 import com.google.common.base.Preconditions;
12 import io.netty.buffer.ByteBuf;
13 import io.netty.buffer.Unpooled;
14 import java.util.List;
15 import org.opendaylight.protocol.bgp.parser.spi.AttributeSerializer;
16 import org.opendaylight.protocol.bgp.parser.spi.AttributeUtil;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.Attributes;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.UnrecognizedAttributes;
19 import org.opendaylight.yangtools.yang.binding.DataObject;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
23 public class UnrecognizedAttributesSerializer implements AttributeSerializer {
24 private static final Logger LOG = LoggerFactory.getLogger(UnrecognizedAttributesSerializer.class);
27 public void serializeAttribute(final DataObject attributes, final ByteBuf byteAggregator) {
28 Preconditions.checkArgument(attributes instanceof Attributes, "Attributes parameter is not a PathAttribute object.");
29 final List<UnrecognizedAttributes> unrecognizedAttrs = ((Attributes) attributes).getUnrecognizedAttributes();
30 if (unrecognizedAttrs == null) {
33 for (final UnrecognizedAttributes unrecognizedAttr: unrecognizedAttrs) {
34 LOG.trace("Serializing unrecognized attribute of type {}", unrecognizedAttr.getType());
35 int flags = AttributeUtil.OPTIONAL;
36 if (unrecognizedAttr.isPartial()) {
37 flags |= AttributeUtil.PARTIAL;
39 if (unrecognizedAttr.isTransitive()) {
40 flags |= AttributeUtil.TRANSITIVE;
42 AttributeUtil.formatAttribute(flags, unrecognizedAttr.getType(), Unpooled.wrappedBuffer(unrecognizedAttr.getValue()), byteAggregator);