use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv6Prefix in project openflowplugin by opendaylight.
the class IpConversionUtil method extractIpv6AddressMask.
@Nullable
public static Ipv6ArbitraryMask extractIpv6AddressMask(final Ipv6Prefix ipv6Prefix) {
Iterator<String> addressParts = PREFIX_SPLITTER.split(ipv6Prefix.getValue()).iterator();
addressParts.next();
int maskLength = 0;
if (addressParts.hasNext()) {
maskLength = Integer.parseInt(addressParts.next());
}
BitSet ipmask = new BitSet(128);
ipmask.set(0, maskLength, true);
ipmask.set(maskLength + 1, 128, false);
byte[] finalmask = new byte[16];
System.arraycopy(ipmask.toByteArray(), 0, finalmask, 0, ipmask.toByteArray().length);
InetAddress inetAddress = null;
try {
inetAddress = InetAddress.getByAddress(finalmask);
} catch (UnknownHostException e) {
LOG.error("Failed to convert the Ipv6 subnetmask from integer to mask value ", e);
return null;
}
return new Ipv6ArbitraryMask(inetAddress.getHostAddress());
}
use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv6Prefix in project openflowplugin by opendaylight.
the class MatchConvertorTest method testIpv6MatchConversionWithMasks.
@Test
public void testIpv6MatchConversionWithMasks() {
MatchBuilder builder = new MatchBuilder();
Ipv6MatchBuilder ipv6Builder = new Ipv6MatchBuilder();
ipv6Builder.setIpv6Source(new Ipv6Prefix("::/24"));
ipv6Builder.setIpv6Destination(new Ipv6Prefix("::/64"));
builder.setLayer3Match(ipv6Builder.build());
Match match = builder.build();
Optional<List<MatchEntry>> entriesOptional = converterManager.convert(match, new VersionConvertorData(OFConstants.OFP_VERSION_1_3));
List<MatchEntry> entries = entriesOptional.get();
Assert.assertEquals("Wrong entries size", 2, entries.size());
MatchEntry entry = entries.get(0);
checkEntryHeader(entry, Ipv6Src.class, true);
Assert.assertEquals("Wrong ipv6 src", "::", ((Ipv6SrcCase) entry.getMatchEntryValue()).getIpv6Src().getIpv6Address().getValue());
Assert.assertArrayEquals("Wrong ipv6 src mask", new byte[] { (byte) 255, (byte) 255, (byte) 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, ((Ipv6SrcCase) entry.getMatchEntryValue()).getIpv6Src().getMask());
entry = entries.get(1);
checkEntryHeader(entry, Ipv6Dst.class, true);
Assert.assertEquals("Wrong ipv6 dst", "::", ((Ipv6DstCase) entry.getMatchEntryValue()).getIpv6Dst().getIpv6Address().getValue());
Assert.assertArrayEquals("Wrong ipv6 src mask", new byte[] { (byte) 255, (byte) 255, (byte) 255, (byte) 255, (byte) 255, (byte) 255, (byte) 255, (byte) 255, 0, 0, 0, 0, 0, 0, 0, 0 }, ((Ipv6DstCase) entry.getMatchEntryValue()).getIpv6Dst().getMask());
}
use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv6Prefix in project lispflowmapping by opendaylight.
the class MaskUtilTest method normalizeTest_withIpv6Prefix.
/**
* Tests {@link MaskUtil#normalize} method with Ipv6Prefix.
*/
@Test
public void normalizeTest_withIpv6Prefix() {
// input ip: 1111:2222:3333:4444:5555:6666:7777:8888, mask: 66
final Eid result = MaskUtil.normalize(EID_IPV6_PREFIX);
final org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv6Prefix resultPrefix = (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv6Prefix) result.getAddress();
// expected result
final String expectedResult = "1111:2222:3333:4444:4000::" + MASK_3;
assertEquals(expectedResult, resultPrefix.getIpv6Prefix().getValue());
}
use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv6Prefix in project lispflowmapping by opendaylight.
the class LispAddressUtil method toEid.
public static Eid toEid(Ipv6Prefix prefix, InstanceIdType vni) {
EidBuilder builder = new EidBuilder();
builder.setAddressType(Ipv6PrefixAfi.class);
builder.setVirtualNetworkId(vni);
builder.setAddress((Address) new Ipv6PrefixBuilder().setIpv6Prefix(prefix).build());
return builder.build();
}
use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv6Prefix 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;
}
Aggregations