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.base.Preconditions;
12 import io.netty.buffer.ByteBuf;
14 import org.opendaylight.protocol.bgp.parser.spi.AttributeParser;
15 import org.opendaylight.protocol.concepts.Ipv4Util;
16 import org.opendaylight.protocol.util.ByteArray;
17 import org.opendaylight.protocol.util.ReferenceCache;
18 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.AsNumber;
19 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.AggregatorBuilder;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.update.PathAttributesBuilder;
23 public final class AggregatorAttributeParser implements AttributeParser {
24 public static final int TYPE = 7;
26 private final ReferenceCache refCache;
28 public AggregatorAttributeParser(final ReferenceCache refCache) {
29 this.refCache = Preconditions.checkNotNull(refCache);
33 * Parse AGGREGATOR from bytes
35 * @param buffer byte buffer to be parsed
36 * @return BGP Aggregator
39 public void parseAttribute(final ByteBuf buffer, final PathAttributesBuilder builder) {
40 final AsNumber asNumber = this.refCache.getSharedReference(new AsNumber(buffer.readUnsignedInt()));
41 final Ipv4Address address = Ipv4Util.addressForBytes(ByteArray.readAllBytes(buffer));
42 builder.setAggregator(new AggregatorBuilder().setAsNumber(asNumber).setNetworkAddress(address).build());