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)
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;
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) {
}
}
+ /**
+ * 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)))));
}
/**
- * 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
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;
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();