2 * Copyright (c) 2013 Cisco 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
8 package org.opendaylight.protocol.bgp.parser.impl.message.update;
10 import com.google.common.collect.Lists;
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.AttributeParser;
15 import org.opendaylight.protocol.bgp.parser.spi.AttributeSerializer;
16 import org.opendaylight.protocol.bgp.parser.spi.AttributeUtil;
17 import org.opendaylight.protocol.util.Ipv4Util;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.Attributes;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.AttributesBuilder;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.attributes.ClusterId;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.attributes.ClusterIdBuilder;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.ClusterIdentifier;
24 public final class ClusterIdAttributeParser implements AttributeParser, AttributeSerializer {
26 public static final int TYPE = 10;
29 public void parseAttribute(final ByteBuf buffer, final AttributesBuilder builder) {
30 final List<ClusterIdentifier> list = Lists.newArrayList();
31 while (buffer.isReadable()) {
32 list.add(new ClusterIdentifier(Ipv4Util.addressForByteBuf(buffer)));
34 builder.setClusterId(new ClusterIdBuilder().setCluster(list).build());
38 public void serializeAttribute(final Attributes pathAttributes, final ByteBuf byteAggregator) {
39 final ClusterId cid = pathAttributes.getClusterId();
43 final List<ClusterIdentifier> cluster = cid.getCluster();
44 if (cluster == null || cluster.isEmpty()) {
47 final ByteBuf clusterIdBuffer = Unpooled.buffer();
48 for (final ClusterIdentifier clusterIdentifier : cid.getCluster()) {
49 clusterIdBuffer.writeBytes(Ipv4Util.bytesForAddress(clusterIdentifier));
51 AttributeUtil.formatAttribute(AttributeUtil.OPTIONAL, TYPE, clusterIdBuffer, byteAggregator);