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
9 package org.opendaylight.protocol.bgp.parser.impl.message.update;
11 import io.netty.buffer.ByteBuf;
13 import java.util.ArrayList;
14 import java.util.List;
16 import org.opendaylight.protocol.util.ReferenceCache;
17 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.AsNumber;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.as.path.segment.c.segment.a.list._case.a.list.AsSequence;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.as.path.segment.c.segment.a.list._case.a.list.AsSequenceBuilder;
23 * Representation of one AS Path Segment. It is, in fact, a TLV, but the length field is representing the count of AS
24 * Numbers in the collection (in its value). If the segment is of type AS_SEQUENCE, the collection is a List, if AS_SET,
25 * the collection is a Set.
28 public final class AsPathSegmentParser {
30 public static final int TYPE_LENGTH = 1;
32 public static final int LENGTH_SIZE = 1;
34 public static final int AS_NUMBER_LENGTH = 4;
37 * Possible types of AS Path segments.
39 public enum SegmentType {
43 private AsPathSegmentParser() {
47 static SegmentType parseType(final int type) {
50 return SegmentType.AS_SET;
52 return SegmentType.AS_SEQUENCE;
58 static List<AsSequence> parseAsSequence(final ReferenceCache refCache, final int count, final ByteBuf buffer) {
59 final List<AsSequence> coll = new ArrayList<>();
60 for (int i = 0; i < count; i++) {
61 coll.add(refCache.getSharedReference(new AsSequenceBuilder().setAs(
62 refCache.getSharedReference(new AsNumber(buffer.readUnsignedInt()))).build()));
67 static List<AsNumber> parseAsSet(final ReferenceCache refCache, final int count, final ByteBuf buffer) {
68 final List<AsNumber> coll = new ArrayList<>();
69 for (int i = 0; i < count; i++) {
70 coll.add(refCache.getSharedReference(new AsNumber(buffer.readUnsignedInt())));