Update MRI projects for Aluminium
[bgpcep.git] / bgp / parser-impl / src / main / java / org / opendaylight / protocol / bgp / parser / impl / message / update / UnrecognizedAttributesSerializer.java
1 /*
2  * Copyright (c) 2016 Brocade Communications Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.protocol.bgp.parser.impl.message.update;
10
11 import io.netty.buffer.ByteBuf;
12 import io.netty.buffer.Unpooled;
13 import java.util.Map;
14 import org.opendaylight.protocol.bgp.parser.spi.AttributeSerializer;
15 import org.opendaylight.protocol.bgp.parser.spi.AttributeUtil;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.Attributes;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.attributes.UnrecognizedAttributes;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.attributes.UnrecognizedAttributesKey;
19 import org.slf4j.Logger;
20 import org.slf4j.LoggerFactory;
21
22 public class UnrecognizedAttributesSerializer implements AttributeSerializer {
23     private static final Logger LOG = LoggerFactory.getLogger(UnrecognizedAttributesSerializer.class);
24
25     @Override
26     public void serializeAttribute(final Attributes attributes, final ByteBuf byteAggregator) {
27         final Map<UnrecognizedAttributesKey, UnrecognizedAttributes> unrecognizedAttrs =
28                 attributes.getUnrecognizedAttributes();
29         if (unrecognizedAttrs == null) {
30             return;
31         }
32         for (final UnrecognizedAttributes unrecognizedAttr : unrecognizedAttrs.values()) {
33             LOG.trace("Serializing unrecognized attribute of type {}", unrecognizedAttr.getType());
34             int flags = AttributeUtil.OPTIONAL;
35             if (unrecognizedAttr.isPartial()) {
36                 flags |= AttributeUtil.PARTIAL;
37             }
38             if (unrecognizedAttr.isTransitive()) {
39                 flags |= AttributeUtil.TRANSITIVE;
40             }
41             AttributeUtil.formatAttribute(flags, unrecognizedAttr.getType().toJava(),
42                     Unpooled.wrappedBuffer(unrecognizedAttr.getValue()), byteAggregator);
43         }
44     }
45
46 }