BUG-45 : migrated Aggregator path attribute to generated source code. 91/1291/2
authorDana Kutenicsova <dkutenic@cisco.com>
Thu, 19 Sep 2013 13:55:27 +0000 (15:55 +0200)
committerDana Kutenicsova <dkutenic@cisco.com>
Thu, 19 Sep 2013 14:00:53 +0000 (16:00 +0200)
Change-Id: I2c1e2dc92d2ba2e7456741f7c557a391ffb82d37
Signed-off-by: Dana Kutenicsova <dkutenic@cisco.com>
bgp/concepts/src/main/java/org/opendaylight/protocol/bgp/concepts/BGPAggregator.java [deleted file]
bgp/concepts/src/main/java/org/opendaylight/protocol/bgp/concepts/BaseBGPObjectState.java
bgp/concepts/src/main/yang/bgp-types.yang
bgp/parser-api/src/main/yang/bgp-message.yang
bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/BGPAggregatorImpl.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/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/ComplementaryTest.java

diff --git a/bgp/concepts/src/main/java/org/opendaylight/protocol/bgp/concepts/BGPAggregator.java b/bgp/concepts/src/main/java/org/opendaylight/protocol/bgp/concepts/BGPAggregator.java
deleted file mode 100644 (file)
index caf6a44..0000000
+++ /dev/null
@@ -1,35 +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 org.opendaylight.protocol.concepts.ASNumber;
-import org.opendaylight.protocol.concepts.NetworkAddress;
-
-/**
- * 
- * BGP Path Attribute AGGREGATOR.
- * 
- * @see <a href="http://tools.ietf.org/html/rfc4271#section-5.1.7">BGP Aggregator</a>
- * 
- */
-public interface BGPAggregator {
-
-       /**
-        * The BGP Speaker returns its own AS Number.
-        * 
-        * @return own AS Number
-        */
-       public ASNumber getASNumber();
-
-       /**
-        * The BGP Speaker returns its own IP Address.
-        * 
-        * @return own IP Address
-        */
-       public NetworkAddress<?> getNetworkAddress();
-}
index 72f9a686715c9559375688883df976a89364006c..d6635242363854a76ca536bfcf60c4d4f519bf30 100644 (file)
@@ -8,6 +8,7 @@
 package org.opendaylight.protocol.bgp.concepts;
 
 import org.opendaylight.protocol.concepts.State;
+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 com.google.common.base.Objects;
@@ -24,15 +25,15 @@ public class BaseBGPObjectState implements State {
        private static final long serialVersionUID = 2371691093534458869L;
 
        private final BgpOrigin origin;
-       private final BGPAggregator aggregator;
+       private final BgpAggregator aggregator;
 
        /**
         * Creates BaswBGPObjectState.
         * 
-        * @param origin {@link BGPOrigin}
-        * @param aggregator {@link BGPAggregator}
+        * @param origin {@link BgpOrigin}
+        * @param aggregator {@link BgpAggregator}
         */
-       public BaseBGPObjectState(final BgpOrigin origin, final BGPAggregator aggregator) {
+       public BaseBGPObjectState(final BgpOrigin origin, final BgpAggregator aggregator) {
                super();
                this.origin = origin;
                this.aggregator = aggregator;
@@ -56,7 +57,7 @@ public class BaseBGPObjectState implements State {
         * 
         * @return BGPAggregator attribute of this object
         */
-       public final BGPAggregator getAggregator() {
+       public final BgpAggregator getAggregator() {
                return this.aggregator;
        }
 
index 1cb9782fa17865581ddee53ce0829a17aae84b15..ecc4c251bb345e3a5a8dafc9a289068ca4bf3f21 100644 (file)
@@ -42,4 +42,15 @@ module bgp-types {
                        }
                }
        }
-}
\ No newline at end of file
+
+       grouping bgp-aggregator {
+               reference "http://tools.ietf.org/html/rfc4271#section-5.1.7";
+               description "BGP Path Attribute AGGREGATOR.";
+               leaf as-number {
+                       type inet:as-number;
+               }
+               leaf network-address {
+                       type inet:ipv4-address;
+               }
+       }
+}
index e642be70462b227d1163854731cf05542ac918ee..5fb769b1047dae86dfdcf2f14a6833432a847fc3 100644 (file)
@@ -36,22 +36,18 @@ module bgp-message {
                }
        }
 
-       typedef as-number {
-               type uint32;
-       }
-
        grouping as-path-segment {
                choice segment {
                        case a-set {
                                leaf-list as-set {
-                                       type as-number;
+                                       type inet:as-number;
                                }
                        }
                        case a-list {
                                list as-sequence {
                                        container sequence {
                                                leaf as {
-                                                       type as-number;
+                                                       type inet:as-number;
                                                }
                                        }
                                }
@@ -85,7 +81,7 @@ module bgp-message {
                                container as4-bytes {
                                        reference "http://tools.ietf.org/html/rfc6793";
                                        leaf as-number {
-                                               type as-number;
+                                               type inet:as-number;
                                        }
                                }
                        }
@@ -131,16 +127,10 @@ module bgp-message {
                        }
                        container atomic-aggregate {
                                reference "http://tools.ietf.org/html/rfc4271#section-5.1.6";
-                               presence "Atomic Aggregare attribute is present.";
+                               presence "Atomic Aggregate attribute is present.";
                        }
                        container aggregator {
-                               reference "http://tools.ietf.org/html/rfc4271#section-5.1.7";
-                               leaf as {
-                                       type as-number;
-                               }
-                               leaf ip {
-                                       type inet:ipv4-address;
-                               }
+                               uses bgp-t:bgp-aggregator;
                        }
                }
                container withdrawn-routes {
index 6b7ed1add505eab5f07368bcbcbe4ac6553d1707..e77fa7686c3cbbb14961347738bcb3c232567675 100644 (file)
@@ -7,34 +7,35 @@
  */
 package org.opendaylight.protocol.bgp.parser.impl;
 
-import org.opendaylight.protocol.bgp.concepts.BGPAggregator;
-
-import org.opendaylight.protocol.concepts.ASNumber;
-import org.opendaylight.protocol.concepts.NetworkAddress;
+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.types.rev130919.BgpAggregator;
 
 /**
- * Implementation of BGP Aggregator object.
+ * Implementation of BGP Aggregator object. RFC4760 assumes that any BGP speaker (including the one that supports
+ * multiprotocol capabilities defined in this document) has to have an IPv4 address (which will be used, among other
+ * things, in the AGGREGATOR attribute).
+ * 
  * @param <T> subtype of Network Address
  */
-public class BGPAggregatorImpl<T extends NetworkAddress<T>> implements
-               BGPAggregator {
+public class BGPAggregatorImpl implements BgpAggregator {
 
-       private final ASNumber asNumber;
+       private final AsNumber asNumber;
 
-       private final T address;
+       private final Ipv4Address address;
 
-       public BGPAggregatorImpl(ASNumber asNumber, T address) {
+       public BGPAggregatorImpl(final AsNumber asNumber, final Ipv4Address address) {
                this.address = address;
                this.asNumber = asNumber;
        }
 
        @Override
-       public ASNumber getASNumber() {
+       public AsNumber getAsNumber() {
                return this.asNumber;
        }
 
        @Override
-       public T getNetworkAddress() {
+       public Ipv4Address getNetworkAddress() {
                return this.address;
        }
 
@@ -43,20 +44,19 @@ public class BGPAggregatorImpl<T extends NetworkAddress<T>> implements
                final int prime = 31;
                int result = 1;
                result = prime * result + ((this.address == null) ? 0 : this.address.hashCode());
-               result = prime * result
-                               + ((this.asNumber == null) ? 0 : this.asNumber.hashCode());
+               result = prime * result + ((this.asNumber == null) ? 0 : this.asNumber.hashCode());
                return result;
        }
 
        @Override
-       public boolean equals(Object obj) {
+       public boolean equals(final Object obj) {
                if (this == obj)
                        return true;
                if (obj == null)
                        return false;
                if (this.getClass() != obj.getClass())
                        return false;
-               final BGPAggregatorImpl<?> other = (BGPAggregatorImpl<?>) obj;
+               final BGPAggregatorImpl other = (BGPAggregatorImpl) obj;
                if (this.address == null) {
                        if (other.address != null)
                                return false;
index 75b48afc52d35b5ad837e6ad539eccb4cf5beab5..54589f087da94f985c4c8eb7cb2053d6692ff235 100644 (file)
@@ -17,7 +17,6 @@ import java.util.Set;
 import javax.annotation.concurrent.NotThreadSafe;
 
 import org.opendaylight.protocol.bgp.concepts.ASPath;
-import org.opendaylight.protocol.bgp.concepts.BGPAggregator;
 import org.opendaylight.protocol.bgp.concepts.BGPObject;
 import org.opendaylight.protocol.bgp.concepts.BaseBGPObjectState;
 import org.opendaylight.protocol.bgp.concepts.Community;
@@ -46,6 +45,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.BgpAggregator;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.BgpOrigin;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -129,7 +129,7 @@ public class BGPUpdateEventBuilder {
                BgpOrigin origin = null;
                ASPath aspath = null;
                IPv4NextHop nextHop = null;
-               BGPAggregator aggregator = null;
+               BgpAggregator aggregator = null;
                final Set<ExtendedCommunity> ecomm = Sets.newHashSet();
                final Set<Community> comm = Sets.newHashSet();
                final Map<Integer, ByteList> linkstate = Maps.newHashMap();
@@ -140,8 +140,8 @@ public class BGPUpdateEventBuilder {
                                aspath = (ASPath) pa.getValue();
                        } else if (pa.getValue() instanceof IPv4NextHop) {
                                nextHop = (IPv4NextHop) pa.getValue();
-                       } else if (pa.getValue() instanceof BGPAggregator) {
-                               aggregator = (BGPAggregator) pa.getValue();
+                       } else if (pa.getValue() instanceof BgpAggregator) {
+                               aggregator = (BgpAggregator) pa.getValue();
                        } else if (pa.getValue() instanceof Set) {
                                for (final Object o : (Set<?>) pa.getValue()) {
                                        if (o instanceof ExtendedCommunity) {
index b92600dce577345fc54593a374c24e4e63e5136c..e5b24ba5199c8d56946a87aacaaf0b3677f720f6 100644 (file)
@@ -12,7 +12,6 @@ import java.util.Map;
 import java.util.Set;
 
 import org.opendaylight.protocol.bgp.concepts.ASPath;
-import org.opendaylight.protocol.bgp.concepts.BGPAggregator;
 import org.opendaylight.protocol.bgp.concepts.ClusterIdentifier;
 import org.opendaylight.protocol.bgp.concepts.Community;
 import org.opendaylight.protocol.bgp.concepts.ExtendedCommunity;
@@ -28,9 +27,13 @@ import org.opendaylight.protocol.bgp.parser.impl.PathAttribute;
 import org.opendaylight.protocol.bgp.parser.impl.PathAttribute.TypeCode;
 import org.opendaylight.protocol.bgp.parser.impl.message.update.AsPathSegmentParser.SegmentType;
 import org.opendaylight.protocol.concepts.ASNumber;
+import org.opendaylight.protocol.concepts.IPv4;
 import org.opendaylight.protocol.concepts.IPv4Address;
 import org.opendaylight.protocol.concepts.NetworkAddress;
 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.types.rev130919.BgpAggregator;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.BgpOrigin;
 
 import com.google.common.collect.Lists;
@@ -221,10 +224,11 @@ public class PathAttributeParser {
         * @param bytes byte array to be parsed
         * @return new BGPAggregator object
         */
-       private static BGPAggregator parseAggregator(final byte[] bytes) {
-               final ASNumber asNumber = new ASNumber(ByteArray.bytesToLong(ByteArray.subByte(bytes, 0, AsPathSegmentParser.AS_NUMBER_LENGTH)));
-               final IPv4Address address = new IPv4Address(ByteArray.subByte(bytes, AsPathSegmentParser.AS_NUMBER_LENGTH, 4));
-               return new BGPAggregatorImpl<IPv4Address>(asNumber, address);
+       private static BgpAggregator parseAggregator(final byte[] bytes) {
+               final AsNumber asNumber = new AsNumber(ByteArray.bytesToLong(ByteArray.subByte(bytes, 0, AsPathSegmentParser.AS_NUMBER_LENGTH)));
+               final Ipv4Address address = new Ipv4Address(IPv4.FAMILY.addressForBytes(
+                               ByteArray.subByte(bytes, AsPathSegmentParser.AS_NUMBER_LENGTH, 4)).toString());
+               return new BGPAggregatorImpl(asNumber, address);
        }
 
        /**
index 09ceef540190702b7e6401448f2b7ba1c0c557ab..ed607bc00554f3491674e4a8beb9235e262407bd 100644 (file)
@@ -24,7 +24,6 @@ import org.junit.BeforeClass;
 import org.junit.Test;
 import org.opendaylight.protocol.bgp.concepts.ASPath;
 import org.opendaylight.protocol.bgp.concepts.BGPAddressFamily;
-import org.opendaylight.protocol.bgp.concepts.BGPAggregator;
 import org.opendaylight.protocol.bgp.concepts.BGPObject;
 import org.opendaylight.protocol.bgp.concepts.BGPSubsequentAddressFamily;
 import org.opendaylight.protocol.bgp.concepts.BGPTableType;
@@ -78,6 +77,9 @@ import org.opendaylight.protocol.concepts.Identifier;
 import org.opendaylight.protocol.concepts.Metric;
 import org.opendaylight.protocol.util.ByteArray;
 import org.opendaylight.protocol.util.DefaultingTypesafeContainer;
+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.types.rev130919.BgpAggregator;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.BgpOrigin;
 
 import com.google.common.collect.Lists;
@@ -415,7 +417,7 @@ public class BGPParserTest {
 
                final ASPath asPath = new ASPath(Lists.newArrayList(new ASNumber(30)), Sets.newHashSet(new ASNumber(10), new ASNumber(20)));
 
-               final BGPAggregator aggregator = new BGPAggregatorImpl<IPv4Address>(new ASNumber(30), IPv4.FAMILY.addressForString("10.0.0.9"));
+               final BgpAggregator aggregator = new BGPAggregatorImpl(new AsNumber((long) 30), new Ipv4Address("10.0.0.9"));
                final IPv4NextHop nextHop = IPv4NextHop.forString("10.0.0.9");
 
                final IPv4Prefix pref1 = IPv4.FAMILY.prefixForString("172.16.0.0/21");
@@ -1093,9 +1095,9 @@ public class BGPParserTest {
 
        @Test
        public void testHashCodeEquals() throws UnknownHostException {
-               final BGPAggregator agg1 = new BGPAggregatorImpl<IPv4Address>(new ASNumber(6), IPv4.FAMILY.addressForString("10.0.0.9"));
+               final BgpAggregator agg1 = new BGPAggregatorImpl(new AsNumber((long) 6), new Ipv4Address("10.0.0.9"));
 
-               final BGPAggregator agg2 = new BGPAggregatorImpl<IPv4Address>(new ASNumber(6), IPv4.FAMILY.addressForString("10.0.0.9"));
+               final BgpAggregator agg2 = new BGPAggregatorImpl(new AsNumber((long) 6), new Ipv4Address("10.0.0.9"));
 
                assertEquals(agg1, agg2);
                assertEquals("HashCodes should be equal", agg1.hashCode(), agg2.hashCode());
index fb3703d16263974739bb2ab2fba58d1097885357..82739c09cee56ef68abc7373de453d775b9a5d00 100644 (file)
@@ -38,10 +38,11 @@ import org.opendaylight.protocol.bgp.parser.impl.message.update.CommunitiesParse
 import org.opendaylight.protocol.bgp.parser.impl.message.update.MPReachParser;
 import org.opendaylight.protocol.concepts.ASNumber;
 import org.opendaylight.protocol.concepts.IPv4;
-import org.opendaylight.protocol.concepts.IPv4Address;
 import org.opendaylight.protocol.concepts.ISOSystemIdentifier;
 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.Ipv4Address;
 
 import com.google.common.collect.Sets;
 
@@ -49,14 +50,14 @@ public class ComplementaryTest {
 
        @Test
        public void testBGPAggregatorImpl() {
-               final BGPAggregatorImpl<IPv4Address> ipv4 = new BGPAggregatorImpl<IPv4Address>(new ASNumber(5524), IPv4.FAMILY.addressForString("124.55.42.1"));
-               final BGPAggregatorImpl<IPv4Address> ipv4i = new BGPAggregatorImpl<IPv4Address>(new ASNumber(5525), IPv4.FAMILY.addressForString("124.55.42.1"));
+               final BGPAggregatorImpl ipv4 = new BGPAggregatorImpl(new AsNumber((long) 5524), new Ipv4Address("124.55.42.1"));
+               final BGPAggregatorImpl ipv4i = new BGPAggregatorImpl(new AsNumber((long) 5525), new Ipv4Address("124.55.42.1"));
 
                assertNotSame(ipv4.hashCode(), ipv4i.hashCode());
 
-               assertEquals(ipv4, new BGPAggregatorImpl<IPv4Address>(new ASNumber(5524), IPv4.FAMILY.addressForString("124.55.42.1")));
+               assertEquals(ipv4, new BGPAggregatorImpl(new AsNumber((long) 5524), new Ipv4Address("124.55.42.1")));
 
-               assertNotSame(ipv4.getASNumber(), ipv4i.getASNumber());
+               assertNotSame(ipv4.getAsNumber(), ipv4i.getAsNumber());
 
                assertEquals(ipv4.getNetworkAddress(), ipv4i.getNetworkAddress());
        }