BUG-45 : migrated Community path attribute to generated code. 57/1357/4
authorDana Kutenicsova <dkutenic@cisco.com>
Mon, 23 Sep 2013 15:22:00 +0000 (17:22 +0200)
committerDana Kutenicsova <dkutenic@cisco.com>
Tue, 24 Sep 2013 13:31:40 +0000 (15:31 +0200)
Change-Id: Id645050b9716d21182098b58a21214ac9edfc7ef
Signed-off-by: Dana Kutenicsova <dkutenic@cisco.com>
21 files changed:
bgp/concepts/src/main/java/org/opendaylight/protocol/bgp/concepts/Community.java [deleted file]
bgp/concepts/src/main/yang/bgp-types.yang
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-api/src/test/java/org/opendaylight/protocol/bgp/parser/APITest.java
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/CommunityUtil.java [new file with mode: 0644]
bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/RouteOriginCommunity.java [moved from bgp/concepts/src/main/java/org/opendaylight/protocol/bgp/concepts/RouteOriginCommunity.java with 88% similarity]
bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/RouteTargetCommunity.java [moved from bgp/concepts/src/main/java/org/opendaylight/protocol/bgp/concepts/RouteTargetCommunity.java with 88% similarity]
bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/BGPOpenMessageParser.java
bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/CommunitiesParser.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-impl/src/test/java/org/opendaylight/protocol/bgp/parser/impl/CommunityTest.java [moved from bgp/concepts/src/test/java/org/opendaylight/protocol/bgp/concepts/CommunityTest.java with 67% similarity]
bgp/parser-impl/src/test/java/org/opendaylight/protocol/bgp/parser/impl/ComplementaryTest.java
bgp/parser-impl/src/test/java/org/opendaylight/protocol/bgp/parser/impl/RouteOriginCommunityTest.java [moved from bgp/concepts/src/test/java/org/opendaylight/protocol/bgp/concepts/RouteOriginCommunityTest.java with 92% similarity]
bgp/parser-impl/src/test/java/org/opendaylight/protocol/bgp/parser/impl/RouteTargetCommunityTest.java [moved from bgp/concepts/src/test/java/org/opendaylight/protocol/bgp/concepts/RouteTargetCommunityTest.java with 92% similarity]
bgp/parser-mock/src/test/java/org/opendaylight/protocol/bgp/parser/mock/BGPMessageParserMockTest.java
bgp/util/src/test/java/org/opendaylight/protocol/bgp/util/LinkTest.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/Community.java b/bgp/concepts/src/main/java/org/opendaylight/protocol/bgp/concepts/Community.java
deleted file mode 100644 (file)
index f184968..0000000
+++ /dev/null
@@ -1,110 +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 org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.AsNumber;
-
-import com.google.common.base.Preconditions;
-
-/**
- * Object representation of a RFC1997 Community tag. Communities are a way for the advertising entitiy to attach
- * semantic meaning/policy to advertised objects.
- */
-public final class Community implements Serializable {
-       /**
-        * NO_EXPORT community. All routes received carrying a communities attribute containing this value MUST NOT be
-        * advertised outside a BGP confederation boundary (a stand-alone autonomous system that is not part of a
-        * confederation should be considered a confederation itself).
-        */
-       public static final Community NO_EXPORT = new Community(new AsNumber((long) 0xFFFF), 0xFF01);
-       /**
-        * NO_ADVERTISE community. All routes received carrying a communities attribute containing this value MUST NOT be
-        * advertised to other BGP peers.
-        */
-       public static final Community NO_ADVERTISE = new Community(new AsNumber((long) 0xFFFF), 0xFF02);
-       /**
-        * NO_EXPORT_SUBCONFED community. All routes received carrying a communities attribute containing this value MUST
-        * NOT be advertised to external BGP peers (this includes peers in other members autonomous systems inside a BGP
-        * confederation).
-        */
-       public static final Community NO_EXPORT_SUBCONFED = new Community(new AsNumber((long) 0xFFFF), 0xFF03);
-
-       private static final long serialVersionUID = -944853598551415685L;
-
-       private final int semantics;
-
-       private final AsNumber as;
-
-       /**
-        * Create a new community tag for a particular AS number and semantics.
-        * 
-        * @param as Global semantics namespace identifier (usually the tagging Autonomous System)
-        * @param semantics Sematics identifier (specific meaning defined externally by the namespace)
-        */
-       public Community(final AsNumber as, final int semantics) {
-               Preconditions.checkArgument(semantics > 0 && semantics < 65535, "Invalid semantics specified");
-               this.semantics = semantics;
-               this.as = as;
-       }
-
-       /**
-        * Return semantics attribute of community.
-        * 
-        * @return Semantics attribute
-        */
-       public int getSemantics() {
-               return this.semantics;
-       }
-
-       /**
-        * Return ASNumber of community.
-        * 
-        * @return {@link AsNumber}
-        */
-       public AsNumber getAs() {
-               return this.as;
-       }
-
-       @Override
-       public boolean equals(final Object o) {
-               if (!(o instanceof Community))
-                       return false;
-
-               final Community c = (Community) o;
-               return this.as.equals(c.as) && this.semantics == c.semantics;
-       }
-
-       @Override
-       public int hashCode() {
-               return 7 * this.as.hashCode() + 13 * this.semantics;
-       }
-
-       @Override
-       public final String toString() {
-               final StringBuilder sb = new StringBuilder(this.as.toString());
-               sb.append(':');
-               sb.append(this.semantics);
-               return sb.toString();
-       }
-
-       /**
-        * Creates a Community from its String representation.
-        * 
-        * @param string String representation of a community
-        * @return new Community
-        */
-       public static Community valueOf(final String string) {
-               final String[] parts = string.split(":", 2);
-
-               final int asn = Integer.valueOf(parts[0]);
-               final int sem = Integer.valueOf(parts[1]);
-               return new Community(new AsNumber((long) asn), sem);
-       }
-}
index 5d157b8454f89c1e8f9b1e12e5804c1fb874b800..6525136cc44fb8f80e61cca7f5abfdb0705af6a2 100644 (file)
@@ -85,4 +85,17 @@ module bgp-types {
                        type inet:ipv4-address;
                }
        }
+
+       grouping community {
+               reference "https://tools.ietf.org/html/rfc1997";
+               description "Community Path Attribute";
+               leaf as-number {
+                       type inet:as-number;
+               }
+               leaf semantics {
+                       type uint32 {
+                               range 0..65535;
+                       }
+               }
+       }
 }
index d9a23c8a72762cd3036a0208ccf3aa5bff4be8db..500316c6a3c1adaa53874e971ed31c8c23da6544 100644 (file)
@@ -11,19 +11,17 @@ import java.util.Collections;
 import java.util.Set;
 
 import org.opendaylight.protocol.bgp.concepts.ASPath;
-import org.opendaylight.protocol.bgp.concepts.Community;
 import org.opendaylight.protocol.bgp.concepts.ExtendedCommunity;
-
 import org.opendaylight.protocol.concepts.Identifier;
-import org.opendaylight.protocol.bgp.linkstate.NetworkObject;
-import org.opendaylight.protocol.bgp.linkstate.NetworkObjectState;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Community;
+
 import com.google.common.base.Objects;
 import com.google.common.base.Objects.ToStringHelper;
 import com.google.common.base.Preconditions;
 
 /**
  * Implementation of {@link NetworkObject}
- *
+ * 
  * @param <T> {@link Identifier} type
  */
 public class NetworkObjectImpl<T extends Identifier> implements NetworkObject<T> {
@@ -32,7 +30,7 @@ public class NetworkObjectImpl<T extends Identifier> implements NetworkObject<T>
        protected NetworkObjectState state;
 
        /**
-        *
+        * 
         * @param name
         */
        public NetworkObjectImpl(final T name) {
@@ -40,7 +38,7 @@ public class NetworkObjectImpl<T extends Identifier> implements NetworkObject<T>
        }
 
        /**
-        *
+        * 
         * @param name T
         * @param template T
         */
@@ -58,33 +56,29 @@ public class NetworkObjectImpl<T extends Identifier> implements NetworkObject<T>
 
        /**
         * Standard setter for NetworkObject asPath attribute.
-        *
-        * @param asPath
-        *            {@link ASPath}
+        * 
+        * @param asPath {@link ASPath}
         */
        public final synchronized void setASPath(final ASPath asPath) {
-               this.state = state.withASPath(asPath);
+               this.state = this.state.withASPath(asPath);
        }
 
        /**
         * Standard setter for NetworkObject communities attribute.
-        *
-        * @param communities
-        *            {@link Community}
+        * 
+        * @param communities {@link CommunityImpl}
         */
        public final synchronized void setCommunities(final Set<Community> communities) {
-               this.state = state.withCommunities(Collections.unmodifiableSet(communities));
+               this.state = this.state.withCommunities(Collections.unmodifiableSet(communities));
        }
 
        /**
         * Standard setter for NetworkObject extendedCommunities attribute.
-        *
-        * @param extendedCommunities
-        *            {@link ExtendedCommunity}
+        * 
+        * @param extendedCommunities {@link ExtendedCommunity}
         */
-       public final synchronized void setExtendedCommunities(
-                       final Set<ExtendedCommunity> extendedCommunities) {
-               this.state = state.withExtendedCommunities(Collections.unmodifiableSet(extendedCommunities));
+       public final synchronized void setExtendedCommunities(final Set<ExtendedCommunity> extendedCommunities) {
+               this.state = this.state.withExtendedCommunities(Collections.unmodifiableSet(extendedCommunities));
        }
 
        @Override
@@ -92,9 +86,9 @@ public class NetworkObjectImpl<T extends Identifier> implements NetworkObject<T>
                return addToStringAttributes(Objects.toStringHelper(this)).toString();
        }
 
-       protected ToStringHelper addToStringAttributes(ToStringHelper toStringHelper) {
-               toStringHelper.add("name", name);
-               toStringHelper.add("state", state);
+       protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
+               toStringHelper.add("name", this.name);
+               toStringHelper.add("state", this.state);
                return toStringHelper;
        }
 
@@ -131,6 +125,6 @@ public class NetworkObjectImpl<T extends Identifier> implements NetworkObject<T>
 
        @Override
        public synchronized NetworkObjectState currentState() {
-               return state;
+               return this.state;
        }
 }
index efad3c1afa893b4a71570d9fd3223b47937fec4c..3f5398284219a0380e03e84d3d43e0e839b55515 100644 (file)
@@ -12,10 +12,10 @@ import java.util.Collections;
 import java.util.Set;
 
 import org.opendaylight.protocol.bgp.concepts.ASPath;
-import org.opendaylight.protocol.bgp.concepts.Community;
 import org.opendaylight.protocol.bgp.concepts.ExtendedCommunity;
-
 import org.opendaylight.protocol.concepts.State;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Community;
+
 import com.google.common.base.Objects;
 import com.google.common.base.Objects.ToStringHelper;
 
index 5fb769b1047dae86dfdcf2f14a6833432a847fc3..489ecad892325e7e7f245217cea37409c54e4b8e 100644 (file)
@@ -132,6 +132,9 @@ module bgp-message {
                        container aggregator {
                                uses bgp-t:bgp-aggregator;
                        }
+                       list communities {
+                               uses bgp-t:community; 
+                       }
                }
                container withdrawn-routes {
                        leaf-list withdrawn-routes {
index dad9807d87cecc4c94926b898be9d5674259be55..ef6b6d4b3d3ae8cddf93c2560d833ead605edadb 100644 (file)
@@ -21,7 +21,6 @@ import java.util.Map;
 import org.junit.Test;
 import org.opendaylight.protocol.bgp.concepts.BGPTableType;
 import org.opendaylight.protocol.bgp.concepts.BaseBGPObjectState;
-import org.opendaylight.protocol.bgp.concepts.Community;
 import org.opendaylight.protocol.bgp.concepts.ExtendedCommunity;
 import org.opendaylight.protocol.bgp.concepts.IPv4NextHop;
 import org.opendaylight.protocol.bgp.linkstate.ISISAreaIdentifier;
@@ -51,6 +50,7 @@ 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.types.rev130919.BgpAddressFamily;
 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.BgpSubsequentAddressFamily;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Community;
 
 import com.google.common.collect.Maps;
 import com.google.common.collect.Sets;
index 54589f087da94f985c4c8eb7cb2053d6692ff235..aece7c4a00777f44724c088f0fced29ebc5e09a5 100644 (file)
@@ -19,7 +19,6 @@ 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.concepts.Community;
 import org.opendaylight.protocol.bgp.concepts.ExtendedCommunity;
 import org.opendaylight.protocol.bgp.concepts.IPv4NextHop;
 import org.opendaylight.protocol.bgp.concepts.IPv6NextHop;
@@ -47,6 +46,7 @@ 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.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.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
diff --git a/bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/CommunityUtil.java b/bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/CommunityUtil.java
new file mode 100644 (file)
index 0000000..c2c0e8e
--- /dev/null
@@ -0,0 +1,64 @@
+/*
+ * 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.parser.impl;
+
+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.message.rev130918.update.path.attributes.CommunitiesBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Community;
+
+/**
+ * Object representation of a RFC1997 Community tag. Communities are a way for the advertising entity to attach semantic
+ * meaning/policy to advertised objects.
+ */
+public final class CommunityUtil {
+       /**
+        * NO_EXPORT community. All routes received carrying a communities attribute containing this value MUST NOT be
+        * advertised outside a BGP confederation boundary (a stand-alone autonomous system that is not part of a
+        * confederation should be considered a confederation itself).
+        */
+       public static final Community NO_EXPORT = CommunityUtil.create(0xFFFF, 0xFF01);
+       /**
+        * NO_ADVERTISE community. All routes received carrying a communities attribute containing this value MUST NOT be
+        * advertised to other BGP peers.
+        */
+       public static final Community NO_ADVERTISE = CommunityUtil.create(0xFFFF, 0xFF02);
+       /**
+        * NO_EXPORT_SUBCONFED community. All routes received carrying a communities attribute containing this value MUST
+        * NOT be advertised to external BGP peers (this includes peers in other members autonomous systems inside a BGP
+        * confederation).
+        */
+       public static final Community NO_EXPORT_SUBCONFED = CommunityUtil.create(0xFFFF, 0xFF03);
+
+       /**
+        * Creates a new Community given AS number value and semantics using generated CommunitiesBuilder.
+        * 
+        * @param asn long
+        * @param semantics long
+        * @return new Community
+        */
+       public static Community create(final long asn, final long semantics) {
+               final CommunitiesBuilder builder = new CommunitiesBuilder();
+               builder.setAsNumber(new AsNumber(asn));
+               builder.setSemantics(semantics);
+               return builder.build();
+       }
+
+       /**
+        * Creates a Community from its String representation.
+        * 
+        * @param string String representation of a community
+        * @return new Community
+        */
+       public static Community valueOf(final String string) {
+               final String[] parts = string.split(":", 2);
+               final CommunitiesBuilder builder = new CommunitiesBuilder();
+               builder.setAsNumber(new AsNumber(Long.valueOf(parts[0])));
+               builder.setSemantics(Long.valueOf(parts[1]));
+               return builder.build();
+       }
+}
similarity index 88%
rename from bgp/concepts/src/main/java/org/opendaylight/protocol/bgp/concepts/RouteOriginCommunity.java
rename to bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/RouteOriginCommunity.java
index 1e37ca125d07c2560702347df1b97324696acfc4..f37d8f421d011403debe0fda67d7396c6297292c 100644 (file)
@@ -6,8 +6,9 @@
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
 
-package org.opendaylight.protocol.bgp.concepts;
+package org.opendaylight.protocol.bgp.parser.impl;
 
+import org.opendaylight.protocol.bgp.concepts.ASSpecificExtendedCommunity;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.AsNumber;
 
 /**
similarity index 88%
rename from bgp/concepts/src/main/java/org/opendaylight/protocol/bgp/concepts/RouteTargetCommunity.java
rename to bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/RouteTargetCommunity.java
index d134e98b834ea2e4b5fcc018bf6a782d083ddcf1..6ac1bd8eac2c2017d52bb1d9bcce8e3717059732 100644 (file)
@@ -5,8 +5,9 @@
  * 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;
+package org.opendaylight.protocol.bgp.parser.impl;
 
+import org.opendaylight.protocol.bgp.concepts.ASSpecificExtendedCommunity;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.AsNumber;
 
 /**
index a652b5e691aeae908d049eac384348ec2361b544..641183fa67d254ff597be98e32db86bbe269e072 100644 (file)
@@ -80,7 +80,7 @@ public final class BGPOpenMessageParser {
 
                // When our AS number does not fit into two bytes, we report it as AS_TRANS
                AsNumber openAS = msg.getMyAS();
-               if (openAS.getValue().longValue() > Integer.MAX_VALUE)
+               if (openAS.getValue().longValue() > 65535)
                        openAS = new AsNumber((long) 2345);
 
                System.arraycopy(ByteArray.longToBytes(openAS.getValue()), 6, msgBody, offset, AS_SIZE);
index 37bbab313e882c0582ce0d4879371a636456d49a..3caabbd8eafad4aa3bdf203fda2f3c4a27ac5c69 100644 (file)
@@ -11,17 +11,18 @@ package org.opendaylight.protocol.bgp.parser.impl.message.update;
 import java.util.Arrays;
 
 import org.opendaylight.protocol.bgp.concepts.ASSpecificExtendedCommunity;
-import org.opendaylight.protocol.bgp.concepts.Community;
 import org.opendaylight.protocol.bgp.concepts.ExtendedCommunity;
 import org.opendaylight.protocol.bgp.concepts.Inet4SpecificExtendedCommunity;
 import org.opendaylight.protocol.bgp.concepts.OpaqueExtendedCommunity;
-import org.opendaylight.protocol.bgp.concepts.RouteOriginCommunity;
-import org.opendaylight.protocol.bgp.concepts.RouteTargetCommunity;
 import org.opendaylight.protocol.bgp.parser.BGPDocumentedException;
 import org.opendaylight.protocol.bgp.parser.BGPError;
+import org.opendaylight.protocol.bgp.parser.impl.CommunityUtil;
+import org.opendaylight.protocol.bgp.parser.impl.RouteOriginCommunity;
+import org.opendaylight.protocol.bgp.parser.impl.RouteTargetCommunity;
 import org.opendaylight.protocol.concepts.IPv4Address;
 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.Community;
 
 import com.google.common.annotations.VisibleForTesting;
 import com.google.common.primitives.UnsignedBytes;
@@ -56,14 +57,14 @@ public class CommunitiesParser {
                if (bytes.length != COMMUNITY_LENGTH)
                        throw new BGPDocumentedException("Community with wrong length: " + bytes.length, BGPError.OPT_ATTR_ERROR);
                if (Arrays.equals(bytes, new byte[] { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0x01 })) {
-                       return Community.NO_EXPORT;
+                       return CommunityUtil.NO_EXPORT;
                } else if (Arrays.equals(bytes, new byte[] { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0x02 })) {
-                       return Community.NO_ADVERTISE;
+                       return CommunityUtil.NO_ADVERTISE;
                } else if (Arrays.equals(bytes, new byte[] { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0x03 })) {
-                       return Community.NO_EXPORT_SUBCONFED;
+                       return CommunityUtil.NO_EXPORT_SUBCONFED;
                }
-               return new Community(new AsNumber(ByteArray.bytesToLong(Arrays.copyOfRange(bytes, 0, AS_NUMBER_LENGTH))), ByteArray.bytesToInt(Arrays.copyOfRange(
-                               bytes, AS_NUMBER_LENGTH, AS_NUMBER_LENGTH + AS_NUMBER_LENGTH)));
+               return CommunityUtil.create((ByteArray.bytesToLong(Arrays.copyOfRange(bytes, 0, AS_NUMBER_LENGTH))),
+                               ByteArray.bytesToLong(Arrays.copyOfRange(bytes, AS_NUMBER_LENGTH, AS_NUMBER_LENGTH + AS_NUMBER_LENGTH)));
        }
 
        /**
index 1fc0c21f56756639ef87cabd16bde0990038bf25..3f88355be3e030c39385fe24576dd125ac4d9131 100644 (file)
@@ -13,7 +13,6 @@ import java.util.Set;
 
 import org.opendaylight.protocol.bgp.concepts.ASPath;
 import org.opendaylight.protocol.bgp.concepts.ClusterIdentifier;
-import org.opendaylight.protocol.bgp.concepts.Community;
 import org.opendaylight.protocol.bgp.concepts.ExtendedCommunity;
 import org.opendaylight.protocol.bgp.concepts.IPv4NextHop;
 import org.opendaylight.protocol.bgp.concepts.NextHop;
@@ -34,6 +33,7 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.
 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.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 com.google.common.collect.Lists;
 import com.google.common.collect.Sets;
index 7d21c1ead6d071a4f328ea28c491b80fb38ee590..a43fc477b9b6336bcb6f37a38227c508e4df39a9 100644 (file)
@@ -17,6 +17,7 @@ import java.io.InputStream;
 import java.net.UnknownHostException;
 import java.util.ArrayList;
 import java.util.Collections;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
 
@@ -26,7 +27,6 @@ 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;
-import org.opendaylight.protocol.bgp.concepts.Community;
 import org.opendaylight.protocol.bgp.concepts.ExtendedCommunity;
 import org.opendaylight.protocol.bgp.concepts.IPv4NextHop;
 import org.opendaylight.protocol.bgp.concepts.IPv6NextHop;
@@ -80,6 +80,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.type
 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.BgpSubsequentAddressFamily;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Community;
 
 import com.google.common.collect.Lists;
 import com.google.common.collect.Sets;
@@ -185,8 +186,11 @@ public class BGPParserTest {
 
                final IPv4NextHop nextHop = IPv4NextHop.forString("10.0.0.2");
 
-               final Set<Community> comms = Sets.newHashSet(Community.NO_EXPORT, Community.NO_ADVERTISE, Community.NO_EXPORT_SUBCONFED,
-                               new Community(new AsNumber((long) 0xFFFF), 0xFF10));
+               final Set<Community> comms = new HashSet<>();
+               comms.add(CommunityUtil.NO_EXPORT);
+               comms.add(CommunityUtil.NO_ADVERTISE);
+               comms.add(CommunityUtil.NO_EXPORT_SUBCONFED);
+               comms.add(CommunityUtil.create(0xFFFF, 0xFF10));
 
                // check path attributes
 
similarity index 67%
rename from bgp/concepts/src/test/java/org/opendaylight/protocol/bgp/concepts/CommunityTest.java
rename to bgp/parser-impl/src/test/java/org/opendaylight/protocol/bgp/parser/impl/CommunityTest.java
index 387a5047134be2120cb0f928b7b2acd153598a72..a16a5963187bfacc84619365fb2db591bf9713f9 100644 (file)
@@ -5,7 +5,7 @@
  * 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;
+package org.opendaylight.protocol.bgp.parser.impl;
 
 import static org.hamcrest.core.IsNot.not;
 import static org.junit.Assert.assertEquals;
@@ -15,29 +15,31 @@ import static org.junit.Assert.assertThat;
 import static org.junit.Assert.fail;
 
 import org.junit.Test;
+import org.opendaylight.protocol.bgp.concepts.ExtendedCommunity;
+import org.opendaylight.protocol.bgp.concepts.OpaqueExtendedCommunity;
 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.Community;
 
 public class CommunityTest {
 
        @Test
        public void testCommunity() {
-               new Community(new AsNumber((long) 10), 222);
-               final AsNumber as = new AsNumber((long) 12);
-               final Community c = new Community(as, 12);
-               assertEquals(as, c.getAs());
-               assertEquals(12, c.getSemantics());
+               CommunityUtil.create(10, 222);
+               final Community c = CommunityUtil.create(12, 12);
+               assertEquals(12, c.getAsNumber().getValue().intValue());
+               assertEquals(12, c.getSemantics().intValue());
        }
 
        @Test
        public void testOverflows() {
                try {
-                       new Community(new AsNumber((long) 10), -2);
+                       CommunityUtil.create(10, -2);
                        fail("Semantics under range.");
                } catch (final IllegalArgumentException e) {
                        assertEquals("Invalid semantics specified", e.getMessage());
                }
                try {
-                       new Community(new AsNumber((long) 10), 65536);
+                       CommunityUtil.create(10, 65536);
                        fail("Semantics above range.");
                } catch (final IllegalArgumentException e) {
                        assertEquals("Invalid semantics specified", e.getMessage());
@@ -46,29 +48,29 @@ public class CommunityTest {
 
        @Test
        public void testEquals() {
-               final Community c1 = new Community(new AsNumber((long) 10), 222);
-               final Community c2 = new Community(new AsNumber((long) 10), 222);
+               final Community c1 = CommunityUtil.create(10, 222);
+               final Community c2 = CommunityUtil.create(10, 222);
                assertEquals(c1, c2);
                assertThat(c1, not(new Object()));
        }
 
        @Test
        public void testHashCode() {
-               final Community c1 = new Community(new AsNumber((long) 10), 222);
-               final Community c2 = new Community(new AsNumber((long) 10), 222);
+               final Community c1 = CommunityUtil.create(10, 222);
+               final Community c2 = CommunityUtil.create(10, 222);
                assertEquals(c1.hashCode(), c2.hashCode());
        }
 
        @Test
        public void testToString() {
-               final Community c = new Community(new AsNumber((long) 10), 222);
+               final Community c = CommunityUtil.create(10, 222);
                assertNotNull(c.toString());
        }
 
        @Test
        public void testValueOf() {
-               final Community comm = Community.valueOf("12:50");
-               assertEquals(comm, new Community(new AsNumber((long) 12), 50));
+               final Community comm = CommunityUtil.valueOf("12:50");
+               assertEquals(comm, CommunityUtil.create(12, 50));
        }
 
        @Test
index 862c07a0bb80c10f99c8913a30720a7737de2137..eaf6328e05da6c3a06b2849001bf6f24f7ab62e1 100644 (file)
@@ -21,8 +21,6 @@ import org.junit.Test;
 import org.opendaylight.protocol.bgp.concepts.ASSpecificExtendedCommunity;
 import org.opendaylight.protocol.bgp.concepts.Inet4SpecificExtendedCommunity;
 import org.opendaylight.protocol.bgp.concepts.OpaqueExtendedCommunity;
-import org.opendaylight.protocol.bgp.concepts.RouteOriginCommunity;
-import org.opendaylight.protocol.bgp.concepts.RouteTargetCommunity;
 import org.opendaylight.protocol.bgp.linkstate.IPv4InterfaceIdentifier;
 import org.opendaylight.protocol.bgp.linkstate.ISISLANIdentifier;
 import org.opendaylight.protocol.bgp.linkstate.ISISRouterIdentifier;
similarity index 92%
rename from bgp/concepts/src/test/java/org/opendaylight/protocol/bgp/concepts/RouteOriginCommunityTest.java
rename to bgp/parser-impl/src/test/java/org/opendaylight/protocol/bgp/parser/impl/RouteOriginCommunityTest.java
index 026986d52ea4f4ff799dc651b91030d26ab5f051..1828e9b6e7bdae67c5e24f734215cbcbf1436768 100644 (file)
@@ -5,7 +5,7 @@
  * 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;
+package org.opendaylight.protocol.bgp.parser.impl;
 
 import static org.junit.Assert.assertArrayEquals;
 import static org.junit.Assert.assertEquals;
@@ -13,6 +13,7 @@ import static org.junit.Assert.assertFalse;
 
 import org.junit.Before;
 import org.junit.Test;
+import org.opendaylight.protocol.bgp.parser.impl.RouteOriginCommunity;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.AsNumber;
 
 public class RouteOriginCommunityTest {
similarity index 92%
rename from bgp/concepts/src/test/java/org/opendaylight/protocol/bgp/concepts/RouteTargetCommunityTest.java
rename to bgp/parser-impl/src/test/java/org/opendaylight/protocol/bgp/parser/impl/RouteTargetCommunityTest.java
index 9606bbd5c80c808814bcce2745594522baa2a9bf..f06dff302f52f4b25a0d3a9c56482d3605743451 100644 (file)
@@ -5,7 +5,7 @@
  * 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;
+package org.opendaylight.protocol.bgp.parser.impl;
 
 import static org.junit.Assert.assertArrayEquals;
 import static org.junit.Assert.assertEquals;
@@ -13,6 +13,7 @@ import static org.junit.Assert.assertFalse;
 
 import org.junit.Before;
 import org.junit.Test;
+import org.opendaylight.protocol.bgp.parser.impl.RouteTargetCommunity;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.AsNumber;
 
 public class RouteTargetCommunityTest {
index f1911ed2fb92f0dbf71436693e675d8736c622a1..aec897a0a4e955b693f09cdc57c778f0d147b3a5 100644 (file)
@@ -29,7 +29,6 @@ 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;
-import org.opendaylight.protocol.bgp.concepts.Community;
 import org.opendaylight.protocol.bgp.concepts.ExtendedCommunity;
 import org.opendaylight.protocol.bgp.concepts.IPv6NextHop;
 import org.opendaylight.protocol.bgp.concepts.NextHop;
@@ -53,6 +52,7 @@ 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.types.rev130919.BgpAddressFamily;
 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.BgpSubsequentAddressFamily;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Community;
 
 import com.google.common.collect.Lists;
 import com.google.common.collect.Maps;
index 003f662d0402c4a8af18697dc6db480e911a5709..47a7e32432d2612329aa5b1aaeab90c8654d191e 100644 (file)
@@ -13,7 +13,6 @@ import java.util.Collections;
 
 import org.junit.Test;
 import org.opendaylight.protocol.bgp.concepts.BaseBGPObjectState;
-import org.opendaylight.protocol.bgp.concepts.Community;
 import org.opendaylight.protocol.bgp.concepts.ExtendedCommunity;
 import org.opendaylight.protocol.bgp.linkstate.LinkIdentifier;
 import org.opendaylight.protocol.bgp.linkstate.LinkProtectionType;
@@ -23,6 +22,7 @@ import org.opendaylight.protocol.bgp.linkstate.TopologyIdentifier;
 import org.opendaylight.protocol.concepts.Metric;
 import org.opendaylight.protocol.util.DefaultingTypesafeContainer;
 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;
 
 public class LinkTest {
 
index 63ad6e090c008414c6fde735cf1f4d24079ca592..ea260e747359439be0e0b8ad621ba9914a3f7cfd 100644 (file)
@@ -15,7 +15,6 @@ 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.concepts.Community;
 import org.opendaylight.protocol.bgp.concepts.ExtendedCommunity;
 import org.opendaylight.protocol.bgp.linkstate.IPv4PrefixIdentifier;
 import org.opendaylight.protocol.bgp.linkstate.IPv6PrefixIdentifier;
@@ -28,6 +27,7 @@ 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.BgpOrigin;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Community;
 
 import com.google.common.collect.Lists;
 import com.google.common.collect.Sets;