MVPN RFC6514 Extendend communities
[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 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.rev180329.path.attributes.Attributes;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.attributes.UnrecognizedAttributes;
19 import org.opendaylight.yangtools.yang.binding.DataObject;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
22
23 public class UnrecognizedAttributesSerializer implements AttributeSerializer {
24     private static final Logger LOG = LoggerFactory.getLogger(UnrecognizedAttributesSerializer.class);
25
26     @Override
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) {
31             return;
32         }
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;
38             }
39             if (unrecognizedAttr.isTransitive()) {
40                 flags |= AttributeUtil.TRANSITIVE;
41             }
42             AttributeUtil.formatAttribute(flags, unrecognizedAttr.getType(), Unpooled.wrappedBuffer(unrecognizedAttr.getValue()), byteAggregator);
43         }
44     }
45
46 }