2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.protocol.concepts;
10 import static org.junit.Assert.assertTrue;
12 import java.net.InetAddress;
13 import java.net.UnknownHostException;
15 import org.junit.Test;
17 import org.opendaylight.protocol.concepts.IPv4;
18 import org.opendaylight.protocol.concepts.IPv4Address;
19 import org.opendaylight.protocol.concepts.IPv6;
20 import org.opendaylight.protocol.concepts.IPv6Address;
22 public class IPAddressesAndPrefixesTest {
26 assertTrue(IPAddresses.parseNetworkAddress("123.123.123.123") instanceof IPv4Address);
27 assertTrue(IPAddresses.parseNetworkAddress("2001::1") instanceof IPv6Address);
30 @Test(expected = IllegalArgumentException.class)
32 IPAddresses.parseNetworkAddress("256.125.126.256");
37 assertTrue("123.123.123.123".equals(IPv4.FAMILY.addressForString("123.123.123.123").toString()));
38 assertTrue("2001:0:0:0:0:0:0:1".equals(IPv6.FAMILY.addressForString("2001::1").toString()));
42 public void test4() throws UnknownHostException{
43 assertTrue(IPAddresses.createNetworkAddress(InetAddress.getByName("123.123.123.123")) instanceof IPv4Address);
44 assertTrue(IPAddresses.createNetworkAddress(InetAddress.getByName("2001::1")) instanceof IPv6Address);
49 assertTrue("123.123.123.0/24".equals(IPv4.FAMILY.addressForString("123.123.123.123").asPrefix(24).toString()));
50 assertTrue("123.123.123.0/24".equals(IPv4.FAMILY.prefixForString("123.123.123.123/24").toString()));
51 assertTrue("2001:0:0:0:0:0:0:0/120".equals(IPv6.FAMILY.addressForString("2001::1").asPrefix(120).toString()));
52 assertTrue("2001:0:0:0:0:0:0:0/120".equals(IPv6.FAMILY.prefixForString("2001::1/120").toString()));