BUG-45 : migrated ASPath to generated source code. 74/1474/1
authorDana Kutenicsova <dkutenic@cisco.com>
Fri, 27 Sep 2013 18:14:03 +0000 (20:14 +0200)
committerDana Kutenicsova <dkutenic@cisco.com>
Fri, 27 Sep 2013 21:21:33 +0000 (23:21 +0200)
Change-Id: I2a8ed29f464318442f15511cf239f34d4f6e5c76
Signed-off-by: Dana Kutenicsova <dkutenic@cisco.com>
12 files changed:
bgp/concepts/src/main/java/org/opendaylight/protocol/bgp/concepts/ASPath.java [deleted file]
bgp/concepts/src/main/yang/bgp-types.yang
bgp/concepts/src/test/java/org/opendaylight/protocol/bgp/concepts/ASPathTest.java [deleted file]
bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/NetworkObjectImpl.java
bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/NetworkObjectState.java
bgp/parser-api/src/main/yang/bgp-message.yang
bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/BGPUpdateEventBuilder.java
bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/AsPathSegmentParser.java
bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/PathAttributeParser.java
bgp/parser-impl/src/test/java/org/opendaylight/protocol/bgp/parser/impl/BGPParserTest.java
bgp/parser-mock/src/test/java/org/opendaylight/protocol/bgp/parser/mock/BGPMessageParserMockTest.java
bgp/util/src/test/java/org/opendaylight/protocol/bgp/util/PrefixTest.java

diff --git a/bgp/concepts/src/main/java/org/opendaylight/protocol/bgp/concepts/ASPath.java b/bgp/concepts/src/main/java/org/opendaylight/protocol/bgp/concepts/ASPath.java
deleted file mode 100644 (file)
index a900489..0000000
+++ /dev/null
@@ -1,128 +0,0 @@
-/*
- * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.protocol.bgp.concepts;
-
-import java.io.Serializable;
-import java.util.Collections;
-import java.util.List;
-import java.util.Set;
-
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.AsNumber;
-
-import com.google.common.base.Objects;
-import com.google.common.base.Objects.ToStringHelper;
-import com.google.common.base.Preconditions;
-
-/**
- * Conceptual representation of an AS path. This class distills the concept behind the encoding rules specified in RFC
- * 4271.
- * 
- * @see <a href="http://tools.ietf.org/html/rfc4271#section-5.1.2">AS Path</a>
- */
-public final class ASPath implements Serializable {
-       /**
-        * An empty AS Path (attribute in all UPDATE messages sent to internal peers).
-        */
-       public static final ASPath EMPTY = new ASPath();
-       private static final long serialVersionUID = 7951172606939897308L;
-       private final Set<AsNumber> aggregatedAsPath;
-       private final List<AsNumber> visibleAsPath;
-
-       private ASPath() {
-               this.visibleAsPath = Collections.emptyList();
-               this.aggregatedAsPath = Collections.emptySet();
-       }
-
-       /**
-        * Construct an AS path object representing a fully-visible path.
-        * 
-        * @param visibleAsPath Ordered list of AS numbers in the path, corresponding to the concatenation of all
-        *        AS_SEQUENCE components.
-        */
-       public ASPath(final List<AsNumber> visibleAsPath) {
-               this.aggregatedAsPath = Collections.emptySet();
-               this.visibleAsPath = Collections.unmodifiableList(Preconditions.checkNotNull(visibleAsPath));
-       }
-
-       /**
-        * Construct an AS path object representing a partially aggregated path.
-        * 
-        * @param visibleAsPath Ordered list of AS numbers in the path, corresponding to the concatenation of all
-        *        AS_SEQUENCE components.
-        * @param aggregatedAsPath Unordered set of AS numbers in the path, corresponding to the concatenation of all AS_SET
-        *        components.
-        */
-       public ASPath(final List<AsNumber> visibleAsPath, final Set<AsNumber> aggregatedAsPath) {
-               Preconditions.checkNotNull(aggregatedAsPath);
-               Preconditions.checkNotNull(visibleAsPath);
-               this.aggregatedAsPath = Collections.unmodifiableSet(aggregatedAsPath);
-               this.visibleAsPath = Collections.unmodifiableList(visibleAsPath);
-       }
-
-       /**
-        * Return the visible part of an AS path. Note that an AS number may be present multiple times in a row due to
-        * "AS number prepend" feature used by many routers to affect route decisions by extending the length on the list
-        * while keeping the loop information intact.
-        * 
-        * @return Ordered list of AS numbers.
-        */
-       public List<AsNumber> getVisibleAsPath() {
-               return this.visibleAsPath;
-       }
-
-       /**
-        * Return the aggregated part of an AS path.
-        * 
-        * @return Unordered set of AS numbers.
-        */
-       public Set<AsNumber> getAggregatedAsPath() {
-               return this.aggregatedAsPath;
-       }
-
-       @Override
-       public int hashCode() {
-               final int prime = 31;
-               int result = 1;
-               result = prime * result + ((this.aggregatedAsPath == null) ? 0 : this.aggregatedAsPath.hashCode());
-               result = prime * result + ((this.visibleAsPath == null) ? 0 : this.visibleAsPath.hashCode());
-               return result;
-       }
-
-       @Override
-       public boolean equals(final Object obj) {
-               if (this == obj)
-                       return true;
-               if (obj == null)
-                       return false;
-               if (this.getClass() != obj.getClass())
-                       return false;
-               final ASPath other = (ASPath) obj;
-               if (this.aggregatedAsPath == null) {
-                       if (other.aggregatedAsPath != null)
-                               return false;
-               } else if (!this.aggregatedAsPath.equals(other.aggregatedAsPath))
-                       return false;
-               if (this.visibleAsPath == null) {
-                       if (other.visibleAsPath != null)
-                               return false;
-               } else if (!this.visibleAsPath.equals(other.visibleAsPath))
-                       return false;
-               return true;
-       }
-
-       @Override
-       public final String toString() {
-               return addToStringAttributes(Objects.toStringHelper(this)).toString();
-       }
-
-       protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
-               toStringHelper.add("aggregatedAsPath", this.aggregatedAsPath);
-               toStringHelper.add("visibleAsPath", this.visibleAsPath);
-               return toStringHelper;
-       }
-}
index 6ab6d2ae804133c8a725a02ffe81d7d115958273..7adec285fc9de197ff8ee1e2790014222b7f74ff 100644 (file)
@@ -194,7 +194,7 @@ module bgp-types {
                        }
                }
        }
-       
+
        grouping next-hop {
                choice c-next-hop {
                        case c-ipv4-next-hop {
@@ -218,4 +218,22 @@ module bgp-types {
                        }
                }
        }
+
+       grouping as-path-segment {
+               reference "http://tools.ietf.org/html/rfc4271#section-5.1.2";
+               choice c-segment {
+                       case c-a-set {
+                               leaf-list as-set {
+                                       type inet:as-number;
+                               }
+                       }
+                       case c-a-list {
+                               list as-sequence {
+                                       leaf as {
+                                               type inet:as-number;
+                                       }
+                               }
+                       }
+               }
+       }
 }
diff --git a/bgp/concepts/src/test/java/org/opendaylight/protocol/bgp/concepts/ASPathTest.java b/bgp/concepts/src/test/java/org/opendaylight/protocol/bgp/concepts/ASPathTest.java
deleted file mode 100644 (file)
index 98b048c..0000000
+++ /dev/null
@@ -1,95 +0,0 @@
-/*
- * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.protocol.bgp.concepts;
-
-import static org.hamcrest.CoreMatchers.equalTo;
-import static org.hamcrest.core.IsNot.not;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertThat;
-
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.AsNumber;
-
-public class ASPathTest {
-
-       private AsNumber asn1, asn2, asn3, asn4, asn5, asn6, asn7, asn8;
-
-       private List<AsNumber> visibleAsPath;
-       private Set<AsNumber> aggregatedAsPath;
-
-       @Before
-       public void init() {
-               this.asn1 = new AsNumber(429496729800L);
-               this.asn2 = new AsNumber((long) 65534);
-               this.asn3 = new AsNumber((long) 200);
-               this.asn4 = new AsNumber(429496729799L);
-               this.asn5 = new AsNumber(425201762503L);
-               this.asn6 = new AsNumber((long) 64538);
-               this.asn7 = new AsNumber((long) 200);
-               this.asn8 = new AsNumber(429496729600L);
-
-               this.visibleAsPath = new ArrayList<AsNumber>();
-               this.aggregatedAsPath = new HashSet<AsNumber>();
-
-               this.visibleAsPath.add(this.asn1);
-               this.visibleAsPath.add(this.asn2);
-               this.visibleAsPath.add(this.asn3);
-               this.visibleAsPath.add(this.asn4);
-
-               this.aggregatedAsPath.add(this.asn5);
-               this.aggregatedAsPath.add(this.asn6);
-               this.aggregatedAsPath.add(this.asn7);
-               this.aggregatedAsPath.add(this.asn8);
-       }
-
-       @Test
-       public void testGetXXXPath() {
-               final ASPath asp1 = ASPath.EMPTY;
-               assertEquals(0, asp1.getVisibleAsPath().size());
-               assertEquals(0, asp1.getAggregatedAsPath().size());
-
-               final ASPath asp2 = new ASPath(this.visibleAsPath);
-               assertEquals(4, asp2.getVisibleAsPath().size());
-               assertEquals(0, asp2.getAggregatedAsPath().size());
-
-               final ASPath asp3 = new ASPath(this.visibleAsPath, this.aggregatedAsPath);
-               assertEquals(4, asp3.getVisibleAsPath().size());
-               assertEquals(4, asp3.getAggregatedAsPath().size());
-       }
-
-       @Test
-       public void testEqualsHashCode() {
-               final ASPath asp1 = ASPath.EMPTY;
-               final ASPath asp2 = asp1;
-               assertEquals(asp1, asp2);
-               assertEquals(asp1.hashCode(), asp2.hashCode());
-               assertNotNull(asp1);
-               assertThat(asp1, not(new Object()));
-
-               final ASPath asp3 = new ASPath(this.visibleAsPath, this.aggregatedAsPath);
-               assertThat(asp1, not(equalTo(asp3)));
-               assertThat(asp1.hashCode(), not(equalTo(asp3.hashCode())));
-
-               final ASPath asp4 = new ASPath(new ArrayList<AsNumber>(), this.aggregatedAsPath);
-               assertThat(asp3, not(equalTo(asp4)));
-       }
-
-       @Test
-       public void testToString() {
-               final ASPath asp = new ASPath(this.visibleAsPath, this.aggregatedAsPath);
-               assertNotNull(asp.toString());
-       }
-
-}
index 2bdbc2b85f4f3abf64645cb7895b4fcd2d9a51ae..731c384efbced27a938cfa13719b793e122b9804 100644 (file)
@@ -8,10 +8,11 @@
 package org.opendaylight.protocol.bgp.linkstate;
 
 import java.util.Collections;
+import java.util.List;
 import java.util.Set;
 
-import org.opendaylight.protocol.bgp.concepts.ASPath;
 import org.opendaylight.protocol.concepts.Identifier;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.AsPathSegment;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Community;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.ExtendedCommunity;
 
@@ -59,7 +60,7 @@ public class NetworkObjectImpl<T extends Identifier> implements NetworkObject<T>
         * 
         * @param asPath {@link ASPath}
         */
-       public final synchronized void setASPath(final ASPath asPath) {
+       public final synchronized void setASPath(final List<AsPathSegment> asPath) {
                this.state = this.state.withASPath(asPath);
        }
 
index 5de6a1c2d76842636b2f8f6055567b688c58c26a..3798233230a9691acd86f8aa306ab13086c40f6f 100644 (file)
@@ -9,10 +9,11 @@
 package org.opendaylight.protocol.bgp.linkstate;
 
 import java.util.Collections;
+import java.util.List;
 import java.util.Set;
 
-import org.opendaylight.protocol.bgp.concepts.ASPath;
 import org.opendaylight.protocol.concepts.State;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.AsPathSegment;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Community;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.ExtendedCommunity;
 
@@ -28,13 +29,14 @@ public class NetworkObjectState implements State {
        private static final long serialVersionUID = 1L;
        private Set<ExtendedCommunity> extendedCommunities;
        private Set<Community> communities;
-       private ASPath asPath;
+       private List<AsPathSegment> asPath;
 
        protected NetworkObjectState() {
-               this(ASPath.EMPTY, Collections.<Community> emptySet(), Collections.<ExtendedCommunity> emptySet());
+               this(Collections.<AsPathSegment> emptyList(), Collections.<Community> emptySet(), Collections.<ExtendedCommunity> emptySet());
        }
 
-       public NetworkObjectState(final ASPath asPath, final Set<Community> communities, final Set<ExtendedCommunity> extendedCommunities) {
+       public NetworkObjectState(final List<AsPathSegment> asPath, final Set<Community> communities,
+                       final Set<ExtendedCommunity> extendedCommunities) {
                this.asPath = asPath;
                this.communities = communities;
                this.extendedCommunities = extendedCommunities;
@@ -52,11 +54,11 @@ public class NetworkObjectState implements State {
         * 
         * @return Path to the advertising Autonomous System.
         */
-       public final ASPath getASPath() {
+       public final List<AsPathSegment> getASPath() {
                return this.asPath;
        }
 
-       public final NetworkObjectState withASPath(final ASPath asPath) {
+       public final NetworkObjectState withASPath(final List<AsPathSegment> asPath) {
                final NetworkObjectState ret = newInstance();
                ret.asPath = asPath;
                return ret;
index a6ad8b7280ef830120c8e7732b485c501f0625db..fdb010dc49ef3a563768688f3084c671a6453034 100644 (file)
@@ -36,26 +36,6 @@ module bgp-message {
                }
        }
 
-       grouping as-path-segment {
-               choice segment {
-                       case a-set {
-                               leaf-list as-set {
-                                       type inet:as-number;
-                               }
-                       }
-                       case a-list {
-                               list as-sequence {
-                                       container sequence {
-                                               leaf as {
-                                                       type inet:as-number;
-                                               }
-                                       }
-                               }
-                       }
-                       mandatory true;
-               }
-       }
-
        notification open {
                description "Open Message";
                reference "http://tools.ietf.org/html/rfc4271#section-4.2";
@@ -100,7 +80,7 @@ module bgp-message {
                container as-path {
                        reference "http://tools.ietf.org/html/rfc4271#section-5.1.2";
                        list segments {
-                               uses as-path-segment;
+                               uses bgp-t:as-path-segment;
                        }
                }
                uses bgp-t:next-hop;
index 5310f0efca0f76795d1efb16616331f92a098265..709b64a542235d76ff697c0c39cb1433ada0d8a7 100644 (file)
@@ -16,7 +16,6 @@ import java.util.Set;
 
 import javax.annotation.concurrent.NotThreadSafe;
 
-import org.opendaylight.protocol.bgp.concepts.ASPath;
 import org.opendaylight.protocol.bgp.concepts.BGPObject;
 import org.opendaylight.protocol.bgp.concepts.BaseBGPObjectState;
 import org.opendaylight.protocol.bgp.linkstate.IPv4PrefixIdentifier;
@@ -41,6 +40,7 @@ import org.opendaylight.protocol.bgp.util.BGPNodeImpl;
 import org.opendaylight.protocol.concepts.IPv4Address;
 import org.opendaylight.protocol.concepts.IPv6Address;
 import org.opendaylight.protocol.concepts.Prefix;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.AsPathSegment;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.BgpAggregator;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.BgpOrigin;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Community;
@@ -50,6 +50,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.type
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import com.google.common.collect.Lists;
 import com.google.common.collect.Maps;
 import com.google.common.collect.Sets;
 
@@ -127,7 +128,7 @@ public class BGPUpdateEventBuilder {
        private Set<BGPObject> fillAddedObjects(final List<PathAttribute> pathAttributes, final Set<Prefix<IPv4Address>> nlri)
                        throws BGPParsingException {
                BgpOrigin origin = null;
-               ASPath aspath = null;
+               final List<AsPathSegment> aspath = Lists.newArrayList();
                CIpv4NextHop nextHop = null;
                BgpAggregator aggregator = null;
                final Set<ExtendedCommunity> ecomm = Sets.newHashSet();
@@ -136,8 +137,12 @@ public class BGPUpdateEventBuilder {
                for (final PathAttribute pa : pathAttributes) {
                        if (pa.getValue() instanceof BgpOrigin) {
                                origin = (BgpOrigin) pa.getValue();
-                       } else if (pa.getValue() instanceof ASPath) {
-                               aspath = (ASPath) pa.getValue();
+                       } else if (pa.getValue() instanceof List) {
+                               for (final Object o : (List<?>) pa.getValue()) {
+                                       if (o instanceof AsPathSegment) {
+                                               aspath.add((AsPathSegment) o);
+                                       }
+                               }
                        } else if (pa.getValue() instanceof CIpv4NextHop) {
                                nextHop = (CIpv4NextHop) pa.getValue();
                        } else if (pa.getValue() instanceof BgpAggregator) {
index ff71f99c350b48572682027011d4bf1116e17568..1007e3e75fd26c8cd40cde0ee60709865e6a4501 100644 (file)
@@ -9,11 +9,12 @@
 package org.opendaylight.protocol.bgp.parser.impl.message.update;
 
 import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashSet;
+import java.util.List;
 
 import org.opendaylight.protocol.util.ByteArray;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.AsNumber;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.as.path.segment.c.segment.c.a.list.AsSequence;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.as.path.segment.c.segment.c.a.list.AsSequenceBuilder;
 
 /**
  * 
@@ -52,8 +53,19 @@ public class AsPathSegmentParser {
                }
        }
 
-       static Collection<AsNumber> parseAsPathSegment(final SegmentType type, final int count, final byte[] bytes) {
-               final Collection<AsNumber> coll = (type == SegmentType.AS_SEQUENCE) ? new ArrayList<AsNumber>() : new HashSet<AsNumber>();
+       static List<AsSequence> parseAsSequence(final int count, final byte[] bytes) {
+               final List<AsSequence> coll = new ArrayList<>();
+               int byteOffset = 0;
+               for (int i = 0; i < count; i++) {
+                       coll.add(new AsSequenceBuilder().setAs(
+                                       new AsNumber(ByteArray.bytesToLong(ByteArray.subByte(bytes, byteOffset, AS_NUMBER_LENGTH)))).build());
+                       byteOffset += AS_NUMBER_LENGTH;
+               }
+               return coll;
+       }
+
+       static List<AsNumber> parseAsSet(final int count, final byte[] bytes) {
+               final List<AsNumber> coll = new ArrayList<>();
                int byteOffset = 0;
                for (int i = 0; i < count; i++) {
                        coll.add(new AsNumber(ByteArray.bytesToLong(ByteArray.subByte(bytes, byteOffset, AS_NUMBER_LENGTH))));
index c70c899588f5a8ad019651a54eda0b5f98259b9d..88fa217973232d04564a0eaefcd0bf637e1bfcc2 100644 (file)
@@ -11,7 +11,6 @@ import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
-import org.opendaylight.protocol.bgp.concepts.ASPath;
 import org.opendaylight.protocol.bgp.parser.BGPDocumentedException;
 import org.opendaylight.protocol.bgp.parser.BGPError;
 import org.opendaylight.protocol.bgp.parser.BGPParsingException;
@@ -28,10 +27,15 @@ import org.opendaylight.protocol.util.ByteArray;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.AsNumber;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.path.attributes.AggregatorBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.path.attributes.as.path.SegmentsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.AsPathSegment;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.BgpAggregator;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.BgpOrigin;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.ClusterIdentifier;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Community;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.as.path.segment.c.segment.CAListBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.as.path.segment.c.segment.CASetBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.as.path.segment.c.segment.c.a.list.AsSequence;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.ExtendedCommunity;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.CNextHop;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.CIpv4NextHopBuilder;
@@ -160,10 +164,10 @@ public class PathAttributeParser {
         * @throws BGPDocumentedException if there is no AS_SEQUENCE present (mandatory)
         * @throws BGPParsingException
         */
-       private static ASPath parseAsPath(final byte[] bytes) throws BGPDocumentedException, BGPParsingException {
+       private static List<AsPathSegment> parseAsPath(final byte[] bytes) throws BGPDocumentedException, BGPParsingException {
                int byteOffset = 0;
-               List<AsNumber> list = null;
-               Set<AsNumber> set = null;
+               final List<AsPathSegment> ases = Lists.newArrayList();
+               boolean isSequence = false;
                while (byteOffset < bytes.length) {
                        final int type = UnsignedBytes.toInt(bytes[byteOffset]);
                        final SegmentType segmentType = AsPathSegmentParser.parseType(type);
@@ -175,18 +179,22 @@ public class PathAttributeParser {
                        byteOffset += AsPathSegmentParser.LENGTH_SIZE;
 
                        if (segmentType == SegmentType.AS_SEQUENCE) {
-                               list = (List<AsNumber>) AsPathSegmentParser.parseAsPathSegment(segmentType, count,
+                               final List<AsSequence> numbers = AsPathSegmentParser.parseAsSequence(count,
                                                ByteArray.subByte(bytes, byteOffset, count * AsPathSegmentParser.AS_NUMBER_LENGTH));
+                               ases.add(new SegmentsBuilder().setCSegment(new CAListBuilder().setAsSequence(numbers).build()).build());
+                               isSequence = true;
                        } else {
-                               set = (Set<AsNumber>) AsPathSegmentParser.parseAsPathSegment(segmentType, count,
+                               final List<AsNumber> list = AsPathSegmentParser.parseAsSet(count,
                                                ByteArray.subByte(bytes, byteOffset, count * AsPathSegmentParser.AS_NUMBER_LENGTH));
+                               ases.add(new SegmentsBuilder().setCSegment(new CASetBuilder().setAsSet(list).build()).build());
+
                        }
                        byteOffset += count * AsPathSegmentParser.AS_NUMBER_LENGTH;
                }
 
-               if (list == null && bytes.length != 0)
+               if (!isSequence && bytes.length != 0)
                        throw new BGPDocumentedException("AS_SEQUENCE must be present in AS_PATH attribute.", BGPError.AS_PATH_MALFORMED);
-               return (set != null) ? new ASPath(list, set) : (list == null) ? ASPath.EMPTY : new ASPath(list);
+               return ases;
        }
 
        /**
index 49ec5c31ba1ebf8f88eecf872957dfaa4c1e92b9..3faef75621bbfa0228e9ca8cbd2e0f424b9d6438 100644 (file)
@@ -23,7 +23,6 @@ import java.util.Set;
 
 import org.junit.BeforeClass;
 import org.junit.Test;
-import org.opendaylight.protocol.bgp.concepts.ASPath;
 import org.opendaylight.protocol.bgp.concepts.BGPObject;
 import org.opendaylight.protocol.bgp.concepts.BGPTableType;
 import org.opendaylight.protocol.bgp.concepts.BaseBGPObjectState;
@@ -74,12 +73,18 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.LinkstateAddressFamily;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.LinkstateSubsequentAddressFamily;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.path.attributes.AggregatorBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.path.attributes.as.path.SegmentsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.AsPathSegment;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.BgpAggregator;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.BgpOrigin;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Community;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv4AddressFamily;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv6AddressFamily;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.UnicastSubsequentAddressFamily;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.as.path.segment.c.segment.CAListBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.as.path.segment.c.segment.CASetBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.as.path.segment.c.segment.c.a.list.AsSequence;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.as.path.segment.c.segment.c.a.list.AsSequenceBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.ExtendedCommunity;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.CInet4SpecificExtendedCommunityBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.c.inet4.specific.extended.community.Inet4SpecificExtendedCommunityBuilder;
@@ -190,7 +195,9 @@ public class BGPParserTest {
 
                // attributes
 
-               final ASPath asPath = new ASPath(Lists.newArrayList(new AsNumber((long) 65002)));
+               final List<AsSequence> asnums = Lists.newArrayList(new AsSequenceBuilder().setAs(new AsNumber(65002L)).build());
+               final List<AsPathSegment> asPath = Lists.newArrayList();
+               asPath.add(new SegmentsBuilder().setCSegment(new CAListBuilder().setAsSequence(asnums).build()).build());
 
                final CIpv4NextHop nextHop = new CIpv4NextHopBuilder().setIpv4NextHop(
                                new Ipv4NextHopBuilder().setGlobal(new Ipv4Address("10.0.0.2")).build()).build();
@@ -314,8 +321,9 @@ public class BGPParserTest {
                assertEquals(Collections.EMPTY_SET, message.getRemovedObjects());
 
                // attributes
-
-               final ASPath asPath = new ASPath(Lists.newArrayList(new AsNumber((long) 65001)));
+               final List<AsSequence> asnums = Lists.newArrayList(new AsSequenceBuilder().setAs(new AsNumber(65001L)).build());
+               final List<AsPathSegment> asPath = Lists.newArrayList();
+               asPath.add(new SegmentsBuilder().setCSegment(new CAListBuilder().setAsSequence(asnums).build()).build());
 
                final CIpv6NextHop nextHop = new CIpv6NextHopBuilder().setIpv6NextHop(
                                new Ipv6NextHopBuilder().setGlobal(new Ipv6Address("2001:db8::1")).setLinkLocal(new Ipv6Address("fe80::c001:bff:fe7e:0")).build()).build();
@@ -419,8 +427,11 @@ public class BGPParserTest {
 
                // attributes
 
-               final ASPath asPath = new ASPath(Lists.newArrayList(new AsNumber((long) 30)), Sets.newHashSet(new AsNumber((long) 10),
-                               new AsNumber((long) 20)));
+               final List<AsSequence> asnums = Lists.newArrayList(new AsSequenceBuilder().setAs(new AsNumber(30L)).build());
+               final List<AsPathSegment> asPath = Lists.newArrayList();
+               asPath.add(new SegmentsBuilder().setCSegment(new CAListBuilder().setAsSequence(asnums).build()).build());
+               asPath.add(new SegmentsBuilder().setCSegment(
+                               new CASetBuilder().setAsSet(Lists.newArrayList(new AsNumber(10L), new AsNumber(20L))).build()).build());
 
                final BgpAggregator aggregator = new AggregatorBuilder().setAsNumber(new AsNumber((long) 30)).setNetworkAddress(
                                new Ipv4Address("10.0.0.9")).build();
@@ -559,7 +570,7 @@ public class BGPParserTest {
                // assertEquals(nlri, ret.getBgpUpdateMessageBuilder().getNlri());
 
                final BaseBGPObjectState state = new BaseBGPObjectState(BgpOrigin.Egp, null);
-               final NetworkRouteState routeState = new NetworkRouteState(new NetworkObjectState(ASPath.EMPTY, Collections.<Community> emptySet(), comms), nextHop);
+               final NetworkRouteState routeState = new NetworkRouteState(new NetworkObjectState(Collections.<AsPathSegment> emptyList(), Collections.<Community> emptySet(), comms), nextHop);
 
                // check API message
 
@@ -872,7 +883,7 @@ public class BGPParserTest {
                assertEquals(Collections.EMPTY_SET, message.getRemovedObjects());
 
                // network object state
-               final NetworkObjectState objState = new NetworkObjectState(ASPath.EMPTY, Collections.<Community> emptySet(), Collections.<ExtendedCommunity> emptySet());
+               final NetworkObjectState objState = new NetworkObjectState(Collections.<AsPathSegment> emptyList(), Collections.<Community> emptySet(), Collections.<ExtendedCommunity> emptySet());
                final BaseBGPObjectState state = new BaseBGPObjectState(BgpOrigin.Igp, null);
 
                // network link state
@@ -1004,7 +1015,7 @@ public class BGPParserTest {
                assertEquals(Collections.EMPTY_SET, message.getRemovedObjects());
 
                // network object state
-               final NetworkObjectState objState = new NetworkObjectState(ASPath.EMPTY, Collections.<Community> emptySet(), Collections.<ExtendedCommunity> emptySet());
+               final NetworkObjectState objState = new NetworkObjectState(Collections.<AsPathSegment> emptyList(), Collections.<Community> emptySet(), Collections.<ExtendedCommunity> emptySet());
                final BaseBGPObjectState state = new BaseBGPObjectState(BgpOrigin.Igp, null);
                final NetworkNodeState nstate = new NetworkNodeState(objState, Collections.<TopologyIdentifier> emptySet(), Collections.<ISISAreaIdentifier> emptySet(), false, false, false, false, Collections.<RouterIdentifier> emptySet(), null);
 
index ba91bbaaad49f75f4de8e89a55b981df9af5a5f6..7d7ce3d22f50177745a3c0f4dd3ce1839e3e784f 100644 (file)
@@ -25,7 +25,6 @@ import java.util.Set;
 
 import org.junit.Before;
 import org.junit.Test;
-import org.opendaylight.protocol.bgp.concepts.ASPath;
 import org.opendaylight.protocol.bgp.concepts.BGPObject;
 import org.opendaylight.protocol.bgp.concepts.BGPTableType;
 import org.opendaylight.protocol.bgp.concepts.BaseBGPObjectState;
@@ -47,10 +46,15 @@ import org.opendaylight.protocol.framework.DeserializerException;
 import org.opendaylight.protocol.framework.DocumentedException;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.AsNumber;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Address;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.path.attributes.as.path.SegmentsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.AsPathSegment;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.BgpOrigin;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Community;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv4AddressFamily;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.MplsLabeledVpnSubsequentAddressFamily;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.as.path.segment.c.segment.CAListBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.as.path.segment.c.segment.c.a.list.AsSequence;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.as.path.segment.c.segment.c.a.list.AsSequenceBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.ExtendedCommunity;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.CNextHop;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.CIpv6NextHopBuilder;
@@ -140,9 +144,9 @@ public class BGPMessageParserMockTest {
         */
        private BGPUpdateMessage fillMessages(final long asn) throws UnknownHostException {
 
-               final List<AsNumber> asnums = new ArrayList<AsNumber>();
-               asnums.add(new AsNumber(asn));
-               final ASPath asPath = new ASPath(asnums);
+               final List<AsSequence> asnums = Lists.newArrayList(new AsSequenceBuilder().setAs(new AsNumber(asn)).build());
+               final List<AsPathSegment> asPath = Lists.newArrayList();
+               asPath.add(new SegmentsBuilder().setCSegment(new CAListBuilder().setAsSequence(asnums).build()).build());
                final CNextHop nextHop = new CIpv6NextHopBuilder().setIpv6NextHop(
                                new Ipv6NextHopBuilder().setGlobal(new Ipv6Address("2001:db8::1")).setLinkLocal(new Ipv6Address("fe80::c001:bff:fe7e:0")).build()).build();
 
index 896de703e10d7766f65000f19ad4809cdf76d3b4..0114d9dbd8140030c02766cb843377ec8f3eca36 100644 (file)
@@ -13,7 +13,6 @@ import static org.junit.Assert.assertNotSame;
 import java.util.Collections;
 
 import org.junit.Test;
-import org.opendaylight.protocol.bgp.concepts.ASPath;
 import org.opendaylight.protocol.bgp.concepts.BaseBGPObjectState;
 import org.opendaylight.protocol.bgp.linkstate.IPv4PrefixIdentifier;
 import org.opendaylight.protocol.bgp.linkstate.IPv6PrefixIdentifier;
@@ -24,17 +23,16 @@ import org.opendaylight.protocol.bgp.linkstate.OSPFRouterIdentifier;
 import org.opendaylight.protocol.bgp.linkstate.RouteTag;
 import org.opendaylight.protocol.concepts.IPv4;
 import org.opendaylight.protocol.concepts.IPv6;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.AsNumber;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.AsPathSegment;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.BgpOrigin;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Community;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.ExtendedCommunity;
 
-import com.google.common.collect.Lists;
 import com.google.common.collect.Sets;
 
 public class PrefixTest {
        final BaseBGPObjectState base = new BaseBGPObjectState(BgpOrigin.Egp, null);
-       final NetworkObjectState state = new NetworkObjectState(new ASPath(Lists.newArrayList(new AsNumber(10L))), Collections.<Community> emptySet(), Collections.<ExtendedCommunity> emptySet());
+       final NetworkObjectState state = new NetworkObjectState(Collections.<AsPathSegment> emptyList(), Collections.<Community> emptySet(), Collections.<ExtendedCommunity> emptySet());
        final NetworkPrefixState prefixState = new NetworkPrefixState(this.state, Sets.<RouteTag> newTreeSet(), null);
 
        final BGPIPv4PrefixImpl r4 = new BGPIPv4PrefixImpl(this.base, new IPv4PrefixIdentifier(new NodeIdentifier(null, null, null, new OSPFRouterIdentifier(new byte[] {