BUG-4593: BGP peer registry lookup false negative result 92/29592/2
authorIveta Halanova <ihalanov@cisco.com>
Thu, 12 Nov 2015 12:15:54 +0000 (13:15 +0100)
committerIveta Halanova <ihalanov@cisco.com>
Thu, 12 Nov 2015 12:37:53 +0000 (12:37 +0000)
Added method into Ipv6Utill for creating Ipv6Address with uncompressed value.
Used when registring and deleting peer address.

Change-Id: Ifa96a3ec2f9f7cc3ee60329e888590647af40f64
Signed-off-by: Iveta Halanova <ihalanov@cisco.com>
(cherry picked from commit 0e5baad314c8374cc1d0dd4bcce9b2845d32da24)

bgp/rib-impl/src/main/java/org/opendaylight/controller/config/yang/bgp/rib/impl/BGPPeerModule.java
util/src/main/java/org/opendaylight/protocol/util/Ipv6Util.java
util/src/test/java/org/opendaylight/protocol/util/IPAddressesAndPrefixesTest.java

index ef91a5a5e69008f0ea9c913c25f48b9277e9657d..377a1948ba4d1c5fefad1625beec94081d51b6f2 100644 (file)
@@ -35,6 +35,7 @@ import org.opendaylight.protocol.bgp.rib.impl.StrictBGPPeerRegistry;
 import org.opendaylight.protocol.bgp.rib.impl.spi.BGPPeerRegistry;
 import org.opendaylight.protocol.bgp.rib.impl.spi.BGPSessionPreferences;
 import org.opendaylight.protocol.bgp.rib.impl.spi.RIB;
+import org.opendaylight.protocol.util.Ipv6Util;
 import org.opendaylight.tcpmd5.api.KeyMapping;
 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.IpAddress;
@@ -202,8 +203,10 @@ public final class BGPPeerModule extends org.opendaylight.controller.config.yang
         Preconditions.checkArgument(host.getIpv4Address() != null || host.getIpv6Address() != null, "Unexpected host %s", host);
         if(host.getIpv4Address() != null) {
             return new IpAddress(host.getIpv4Address());
+        } else if(host.getIpv6Address() != null){
+            return new IpAddress(Ipv6Util.getFullForm(host.getIpv6Address()));
         }
-        return new IpAddress(host.getIpv6Address());
+        throw new IllegalArgumentException("Unexpected host " + host);
     }
 
     private io.netty.util.concurrent.Future<Void> initiateConnection(final InetSocketAddress address, final Optional<Rfc2385Key> password, final BGPPeerRegistry registry) {
index 74ad1ac44a0ddf60c7ab23682af2c3c39161d694..cdff9665f81c101f97af911ca2008a72fbbf110e 100644 (file)
@@ -49,11 +49,21 @@ public final class Ipv6Util {
         }
     }
 
+    /**
+     * Creates uncompressed IP Address
+     *
+     * @param ip to be uncompressed
+     * @return Ipv6Address with same, but uncompressed, value
+     */
+    public static Ipv6Address getFullForm(final Ipv6Address ip) {
+        return new Ipv6Address(InetAddresses.forString(ip.getValue()).getHostAddress());
+    }
+
     /**
      * Reads from ByteBuf buffer and converts bytes to Ipv6Address.
      *
      * @param buffer containing Ipv6 address, starting at reader index
-     * @return Ipv4Address
+     * @return Ipv6Address
      */
     public static Ipv6Address addressForByteBuf(final ByteBuf buffer) {
         return new Ipv6Address(InetAddresses.toAddrString(getAddress((ByteArray.readBytes(buffer, IPV6_LENGTH)))));
@@ -96,7 +106,7 @@ public final class Ipv6Util {
     }
 
     /**
-     * Converts Ipv4Prefix to byte array. Prefix length at the beginning.
+     * Converts Ipv6Prefix to byte array. Prefix length at the beginning.
      * Prefix bytes are trimmed from the end to match prefix length.
      *
      * @param prefix Ipv6Prefix to be converted
index 4366d5862ea721a8bc4ba41c971d246ff815cde3..f502ce08265da1755dbe0da34fe961bd41c78e83 100644 (file)
@@ -13,7 +13,6 @@ import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
-
 import com.google.common.collect.Lists;
 import com.google.common.net.InetAddresses;
 import io.netty.buffer.ByteBuf;
@@ -176,6 +175,11 @@ public class IPAddressesAndPrefixesTest {
         assertTrue(prefs.isEmpty());
     }
 
+    @Test
+    public void testFullFormOfIpv6() {
+        assertEquals(new Ipv6Address("0:0:0:0:0:0:0:1"), Ipv6Util.getFullForm(new Ipv6Address("::1")));
+    }
+
     @Test(expected=UnsupportedOperationException.class)
     public void testIpv4UtilPrivateConstructor() throws Throwable {
         final Constructor<Ipv4Util> c = Ipv4Util.class.getDeclaredConstructor();