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 org.opendaylight.protocol.bgp.parser.spi.AttributeParser;
11 import org.opendaylight.protocol.concepts.Ipv4Util;
12 import org.opendaylight.protocol.util.ByteArray;
13 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.AsNumber;
14 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.Aggregator;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.AggregatorBuilder;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.update.PathAttributesBuilder;
19 public final class AggregatorAttributeParser implements AttributeParser {
20 public static final int TYPE = 7;
23 * Parse AGGREGATOR from bytes
25 * @param bytes byte array to be parsed
26 * @return {@link Aggregator} BGP Aggregator
28 private static Aggregator parseAggregator(final byte[] bytes) {
29 final AsNumber asNumber = new AsNumber(ByteArray.bytesToLong(ByteArray.subByte(bytes, 0, AsPathSegmentParser.AS_NUMBER_LENGTH)));
30 final Ipv4Address address = Ipv4Util.addressForBytes(ByteArray.subByte(bytes, AsPathSegmentParser.AS_NUMBER_LENGTH, 4));
31 return new AggregatorBuilder().setAsNumber(asNumber).setNetworkAddress(address).build();
35 public void parseAttribute(final byte[] bytes, final PathAttributesBuilder builder) {
36 builder.setAggregator(parseAggregator(bytes));