YANG revision dates mass-update
[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.List;
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.slf4j.Logger;
19 import org.slf4j.LoggerFactory;
20
21 public class UnrecognizedAttributesSerializer implements AttributeSerializer {
22     private static final Logger LOG = LoggerFactory.getLogger(UnrecognizedAttributesSerializer.class);
23
24     @Override
25     public void serializeAttribute(final Attributes attributes, final ByteBuf byteAggregator) {
26         final List<UnrecognizedAttributes> unrecognizedAttrs = attributes.getUnrecognizedAttributes();
27         if (unrecognizedAttrs == null) {
28             return;
29         }
30         for (final UnrecognizedAttributes unrecognizedAttr : unrecognizedAttrs) {
31             LOG.trace("Serializing unrecognized attribute of type {}", unrecognizedAttr.getType());
32             int flags = AttributeUtil.OPTIONAL;
33             if (unrecognizedAttr.isPartial()) {
34                 flags |= AttributeUtil.PARTIAL;
35             }
36             if (unrecognizedAttr.isTransitive()) {
37                 flags |= AttributeUtil.TRANSITIVE;
38             }
39             AttributeUtil.formatAttribute(flags, unrecognizedAttr.getType().toJava(),
40                     Unpooled.wrappedBuffer(unrecognizedAttr.getValue()), byteAggregator);
41         }
42     }
43
44 }