Change types of CLUSTER_ID and ORIGINATOR 28/4828/1
authorRobert Varga <rovarga@cisco.com>
Sun, 26 Jan 2014 21:56:31 +0000 (22:56 +0100)
committerRobert Varga <rovarga@cisco.com>
Sun, 26 Jan 2014 21:56:31 +0000 (22:56 +0100)
Change-Id: I78b613543a3715ad067b68bdae7d26a6ff665bce
Signed-off-by: Robert Varga <rovarga@cisco.com>
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/message/update/ClusterIdAttributeParser.java
bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/OriginatorIdAttributeParser.java
bgp/parser-impl/src/test/java/org/opendaylight/protocol/bgp/parser/impl/BGPParserTest.java
bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/BGPObjectComparator.java
bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/BestPathSelectionTest.java

index 39e51c1fedf2fc7cb80ded1c743a4922ce20da22..17c9987e37a92d6066d71be824d13a757f471577 100644 (file)
@@ -70,9 +70,7 @@ module bgp-types {
 
        typedef cluster-identifier {
                reference "http://tools.ietf.org/html/rfc4456#section-8";
-               type binary {
-                       length "4";
-               }
+               type inet:ipv4-address;
        }
 
        typedef short-as-number {
index 27a7e6a62696f58a0554a2405e8cb1dcf9bc03cb..c3e9f1e145154e9b1358dce98187f4279e048929 100644 (file)
@@ -113,9 +113,7 @@ module bgp-message {
                        uses bgp-t:extended-community;
                }
                leaf originator-id {
-                       type binary {
-                               length "4";
-                       }
+                       type inet:ipv4-address;
                }
                leaf-list cluster-id {
                        type bgp-t:cluster-identifier;
index ff9b734564463f0b4e231bbe1a6df0a5cf234520..b6bc009d7a8a9126d1f504f32456da0455954c72 100644 (file)
@@ -10,6 +10,7 @@ package org.opendaylight.protocol.bgp.parser.impl.message.update;
 import java.util.List;
 
 import org.opendaylight.protocol.bgp.parser.spi.AttributeParser;
+import org.opendaylight.protocol.concepts.Ipv4Util;
 import org.opendaylight.protocol.util.ByteArray;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.update.PathAttributesBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.ClusterIdentifier;
@@ -26,7 +27,7 @@ public final class ClusterIdAttributeParser implements AttributeParser {
                final List<ClusterIdentifier> list = Lists.newArrayList();
                int i = 0;
                while (i < bytes.length) {
-                       list.add(new ClusterIdentifier(ByteArray.subByte(bytes, i, CLUSTER_LENGTH)));
+                       list.add(new ClusterIdentifier(Ipv4Util.addressForBytes(ByteArray.subByte(bytes, i, CLUSTER_LENGTH))));
                        i += CLUSTER_LENGTH;
                }
 
index 914d84ae61c6d3f80abc243185959123963234ae..42a79277b9227bc32085d70e36e5142000c2897a 100644 (file)
@@ -8,6 +8,7 @@
 package org.opendaylight.protocol.bgp.parser.impl.message.update;
 
 import org.opendaylight.protocol.bgp.parser.spi.AttributeParser;
+import org.opendaylight.protocol.concepts.Ipv4Util;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.update.PathAttributesBuilder;
 
 public final class OriginatorIdAttributeParser implements AttributeParser {
@@ -21,6 +22,6 @@ public final class OriginatorIdAttributeParser implements AttributeParser {
                        throw new IllegalArgumentException("Length of byte array for ORIGINATOR_ID should be " + ORIGINATOR_LENGTH + ", but is "
                                        + bytes.length);
                }
-               builder.setOriginatorId(bytes);
+               builder.setOriginatorId(Ipv4Util.addressForBytes(bytes));
        }
 }
\ No newline at end of file
index 682e6da6b3cfee051f37fef204152723ab19ac8d..61d0f63c2937fa2fb4436983b65240b90264bc88 100644 (file)
@@ -7,7 +7,6 @@
  */
 package org.opendaylight.protocol.bgp.parser.impl;
 
-import static org.junit.Assert.assertArrayEquals;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
@@ -349,8 +348,8 @@ public class BGPParserTest {
                final Ipv6NextHopCase nextHop = new Ipv6NextHopCaseBuilder().setIpv6NextHop(
                                new Ipv6NextHopBuilder().setGlobal(new Ipv6Address("2001:db8::1")).setLinkLocal(new Ipv6Address("fe80::c001:bff:fe7e:0")).build()).build();
 
-               final List<ClusterIdentifier> clusters = Lists.newArrayList(new ClusterIdentifier(new byte[] { 1, 2, 3, 4 }),
-                               new ClusterIdentifier(new byte[] { 5, 6, 7, 8 }));
+               final List<ClusterIdentifier> clusters = Lists.newArrayList(new ClusterIdentifier(new Ipv4Address("1.2.3.4")),
+                               new ClusterIdentifier(new Ipv4Address("5.6.7.8")));
 
                // check path attributes
 
@@ -367,8 +366,8 @@ public class BGPParserTest {
                paBuilder.setMultiExitDisc(new MultiExitDiscBuilder().setMed((long) 0).build());
                assertEquals(paBuilder.getMultiExitDisc(), attrs.getMultiExitDisc());
 
-               paBuilder.setOriginatorId(new byte[] { 127, 0, 0, 1 });
-               assertArrayEquals(paBuilder.getOriginatorId(), attrs.getOriginatorId());
+               paBuilder.setOriginatorId(new Ipv4Address("127.0.0.1"));
+               assertEquals(paBuilder.getOriginatorId(), attrs.getOriginatorId());
 
                paBuilder.setClusterId(clusters);
                assertEquals(paBuilder.getClusterId(), attrs.getClusterId());
index d8932eec7825c4a7951da77eac3cfcd0c8736dbd..1436b4f586c6840bcdea8bbae57449e832b687b2 100644 (file)
@@ -19,6 +19,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.as.path.segment.c.segment.ASetCase;
 
 import com.google.common.annotations.VisibleForTesting;
+import com.google.common.net.InetAddresses;
 
 /**
  * This comparator is intended to implement BGP Best Path Selection algorithm, as described at
@@ -121,10 +122,10 @@ final class BGPObjectComparator implements Comparator<PathAttributes> {
                byte[] oid1 = this.id1;
                byte[] oid2 = this.id2;
                if (o1.getOriginatorId() != null) {
-                       oid1 = o1.getOriginatorId();
+                       oid1 = InetAddresses.forString(o1.getOriginatorId().getValue()).getAddress();
                }
                if (o2.getOriginatorId() != null) {
-                       oid2 = o2.getOriginatorId();
+                       oid2 = InetAddresses.forString(o2.getOriginatorId().getValue()).getAddress();
                }
                if (!Arrays.equals(oid1, oid2)) {
                        return compareByteArrays(oid1, oid2);
index 0dac242737fd8374d132aab8736f135d4ca053c9..92f6208ceb07e03a4372857c48681754136f8525 100644 (file)
@@ -15,6 +15,7 @@ import java.util.List;
 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;
+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.rev130919.PathAttributes;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.AsPathBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.LocalPrefBuilder;
@@ -41,7 +42,7 @@ import com.google.common.collect.Lists;
 public class BestPathSelectionTest {
 
        private final BGPObjectComparator comparator = new BGPObjectComparator(new AsNumber(40L), new byte[] { (byte) 192, (byte) 150, 20, 38 }, new byte[] {
-                       (byte) 192, (byte) 150, 20, 38 });
+               (byte) 192, (byte) 150, 20, 38 });
 
        private PathAttributes attr1;
        private PathAttributes attr2;
@@ -66,8 +67,8 @@ public class BestPathSelectionTest {
                asBuilder2.setSegments(segs);
 
                final List<ClusterIdentifier> clusters = new ArrayList<>();
-               clusters.add(new ClusterIdentifier(new byte[4]));
-               clusters.add(new ClusterIdentifier(new byte[4]));
+               clusters.add(new ClusterIdentifier(new Ipv4Address("0.0.0.0")));
+               clusters.add(new ClusterIdentifier(new Ipv4Address("0.0.0.0")));
 
                final PathAttributesBuilder builder = new PathAttributesBuilder();
                builder.setLocalPref(new LocalPrefBuilder().setPref(100L).build());