use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv4Prefix in project lispflowmapping by opendaylight.
the class MaskUtil method normalize.
public static Eid normalize(Eid eid, short mask) {
Address address = eid.getAddress();
try {
if (address instanceof Ipv4PrefixBinary) {
byte[] addr = ((Ipv4PrefixBinary) address).getIpv4AddressBinary().getValue();
return LispAddressUtil.asIpv4PrefixBinaryEid(eid, normalizeByteArray(addr, mask), mask);
} else if (address instanceof Ipv6PrefixBinary) {
byte[] addr = ((Ipv6PrefixBinary) address).getIpv6AddressBinary().getValue();
return LispAddressUtil.asIpv6PrefixBinaryEid(eid, normalizeByteArray(addr, mask), mask);
} else if (address instanceof Ipv4Prefix) {
final String addr = getPrefixAddress(((Ipv4Prefix) address).getIpv4Prefix().getValue());
InetAddress normalized = normalizeIP(InetAddresses.forString(addr), mask);
return LispAddressUtil.asIpv4PrefixEid(eid, (Inet4Address) normalized, mask);
} else if (address instanceof Ipv6Prefix) {
final String addr = getPrefixAddress(((Ipv6Prefix) address).getIpv6Prefix().getValue());
InetAddress normalized = normalizeIP(InetAddresses.forString(addr), mask);
return LispAddressUtil.asIpv6PrefixEid(eid, (Inet6Address) normalized, mask);
} else if (address instanceof InstanceId) {
// TODO - not absolutely necessary, but should be implemented
return eid;
}
} catch (UnknownHostException e) {
LOG.warn("Failed to normalize EID {} with mask {}, returning original EID", eid, mask, e);
}
return eid;
}
use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv4Prefix in project lispflowmapping by opendaylight.
the class LispAddressUtilTest method addressFromSimpleAddressTest_asIpPrefix.
/**
* Tests {@link LispAddressUtil#addressTypeFromSimpleAddress} and {@link
* LispAddressUtil#addressFromSimpleAddress} methods
* with ipPrefix.
*/
@Test
public void addressFromSimpleAddressTest_asIpPrefix() {
final SimpleAddress simpleAddress = new SimpleAddress(new IpPrefix(new Ipv4Prefix(IPV4_ADDRESS_PREFIX_VALUE_TEST)));
final Class<? extends LispAddressFamily> addressClass = LispAddressUtil.addressTypeFromSimpleAddress(simpleAddress);
assertEquals(Ipv4PrefixAfi.class, addressClass);
final Address address = LispAddressUtil.addressFromSimpleAddress(simpleAddress);
assertTrue(address instanceof org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv4Prefix);
}
use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv4Prefix in project lispflowmapping by opendaylight.
the class LispAddressUtilTest method verifyEidContainsIpPrefix.
public void verifyEidContainsIpPrefix(final Eid eid, final short mask) {
final Ipv4Prefix expectedPrefix = new Ipv4Prefix(IPV4_ADDRESS_VALUE_TEST + "/" + mask);
assertNotNull(eid);
assertTrue(eid.getAddress() instanceof org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv4Prefix);
final org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv4Prefix address = (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv4Prefix) eid.getAddress();
assertEquals(expectedPrefix, address.getIpv4Prefix());
}
use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv4Prefix in project lispflowmapping by opendaylight.
the class LispAddressUtilTest method convertToBinaryTest_eid.
/**
* Tests {@link LispAddressUtil#convertToBinary(Eid)} method with ipv4Prefix, ipv6Prefix, ipv4, ipv6.
*/
@Test
public void convertToBinaryTest_eid() {
final Eid ipv4PrefixEid = new EidBuilder().setAddress(IPV4_PREFIX).build();
final Eid ipv6PrefixEid = new EidBuilder().setAddress(IPV6_PREFIX).build();
final Eid ipv4 = new EidBuilder().setAddress(IPV4).build();
final Eid ipv6 = new EidBuilder().setAddress(IPV6).build();
Eid resultIpv4PrefixBinary = LispAddressUtil.convertToBinary(ipv4PrefixEid);
verifyToEidWithIpv4PrefixBinary(resultIpv4PrefixBinary, false, MASK_OK_TEST, Ipv4PrefixBinaryAfi.class);
Eid resultIpv6PrefixBinary = LispAddressUtil.convertToBinary(ipv6PrefixEid);
verifyToEidWithIpv6PrefixBinary(resultIpv6PrefixBinary, false, MASK_OK_TEST, Ipv6PrefixBinaryAfi.class);
Eid resultIpv4Binary = LispAddressUtil.convertToBinary(ipv4);
verifyToEidWithIpv4Binary(resultIpv4Binary, false);
Eid resultIpv6Binary = LispAddressUtil.convertToBinary(ipv6);
verifyToEidWithIpv6Binary(resultIpv6Binary, false);
}
use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv4Prefix in project lispflowmapping by opendaylight.
the class LispAddressUtilTest method convertFromBinaryTest_eid.
/**
* Tests {@link LispAddressUtil#convertToBinary(Eid)} method with ipv4Prefix, ipv6Prefix, ipv4, ipv6.
*/
@Test
public void convertFromBinaryTest_eid() {
final Eid resultIpv4Prefix = LispAddressUtil.convertFromBinary(IPV4_ADDRESS_PREFIX_BINARY_EID_1);
verifyToEidWithIpv4Prefix(resultIpv4Prefix, false, MASK_OK_TEST, Ipv4PrefixAfi.class);
final Eid resultIpv6Prefix = LispAddressUtil.convertFromBinary(IPV6_ADDRESS_PREFIX_BINARY_EID_1);
verifyToEidWithIpv6Prefix(resultIpv6Prefix, false, MASK_OK_TEST, Ipv6PrefixAfi.class);
final Eid resultIpv4 = LispAddressUtil.convertFromBinary(IPV4_ADDRESS_BINARY_EID);
verifyToEidWithIpv4(resultIpv4, false);
final Eid resultIpv6 = LispAddressUtil.convertFromBinary(IPV6_ADDRESS_BINARY_EID);
verifyToEidWithIpv6(resultIpv6, false);
}
Aggregations