use of org.opendaylight.yang.gen.v1.urn.opendaylight.opendaylight.ipv6.arbitrary.bitmask.fields.rev160224.Ipv6ArbitraryMask in project openflowplugin by opendaylight.
the class Ipv6ArbitraryBitMaskDestinationEntrySerializerTest method testSerialize.
@Test
public void testSerialize() throws Exception {
final Ipv6Address ipv6Address = new Ipv6Address("aaaa:bbbb:1111:2222::");
final Ipv6ArbitraryMask ipv6mask = new Ipv6ArbitraryMask("ffff:ffff:ffff:ffff::");
final Match ipv6abmMatch = new MatchBuilder().setLayer3Match(new Ipv6MatchArbitraryBitMaskBuilder().setIpv6DestinationAddressNoMask(ipv6Address).setIpv6DestinationArbitraryBitmask(ipv6mask).build()).build();
assertMatch(ipv6abmMatch, true, (out) -> {
byte[] address = new byte[16];
out.readBytes(address);
assertArrayEquals(address, IetfInetUtil.INSTANCE.ipv6AddressBytes(ipv6Address));
byte[] mask = new byte[16];
out.readBytes(mask);
assertArrayEquals(mask, IpConversionUtil.convertIpv6ArbitraryMaskToByteArray(ipv6mask));
});
final Match ipv6abmMatchNoMask = new MatchBuilder().setLayer3Match(new Ipv6MatchArbitraryBitMaskBuilder().setIpv6DestinationAddressNoMask(ipv6Address).build()).build();
assertMatch(ipv6abmMatchNoMask, false, (out) -> {
byte[] address = new byte[16];
out.readBytes(address);
assertArrayEquals(address, IetfInetUtil.INSTANCE.ipv6AddressBytes(ipv6Address));
});
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.opendaylight.ipv6.arbitrary.bitmask.fields.rev160224.Ipv6ArbitraryMask in project openflowplugin by opendaylight.
the class IpConversionUtilTest method convertipv6ArbitraryMaskToByteArrayTest.
@Test
public void convertipv6ArbitraryMaskToByteArrayTest() {
byte[] bytes = { -5, -96, -1, -74, -1, -16, -1, -16, -1, -16, -1, -16, -1, -16, -91, 85 };
byte[] maskBytes = IpConversionUtil.convertIpv6ArbitraryMaskToByteArray(new Ipv6ArbitraryMask("fbA0:FFB6:FFF0:FFF0:FFF0:FFF0:FFF0:A555"));
for (int i = 0; i < bytes.length; i++) {
int mask = maskBytes[i];
Assert.assertEquals(bytes[i], mask);
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.opendaylight.ipv6.arbitrary.bitmask.fields.rev160224.Ipv6ArbitraryMask in project openflowplugin by opendaylight.
the class IpConversionUtilTest method createIpv6ArbitraryBitMaskTest.
@Test
public void createIpv6ArbitraryBitMaskTest() {
byte[] bytes = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 };
Ipv6ArbitraryMask ipv6ArbitraryMask;
ipv6ArbitraryMask = IpConversionUtil.createIpv6ArbitraryBitMask(bytes);
Assert.assertEquals(ipv6ArbitraryMask.getValue(), "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff");
Ipv6ArbitraryMask ipv6ArbitraryMaskNull;
ipv6ArbitraryMaskNull = IpConversionUtil.createIpv6ArbitraryBitMask(null);
Assert.assertEquals(ipv6ArbitraryMaskNull.getValue(), "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff");
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.opendaylight.ipv6.arbitrary.bitmask.fields.rev160224.Ipv6ArbitraryMask in project openflowplugin by opendaylight.
the class OfToSalIpv6SrcCase method process.
@Override
public Optional<MatchBuilder> process(@Nonnull Ipv6SrcCase source, MatchResponseConvertorData data, ConvertorExecutor convertorExecutor) {
final MatchBuilder matchBuilder = data.getMatchBuilder();
final Ipv6MatchBuilder ipv6MatchBuilder = data.getIpv6MatchBuilder();
final Ipv6MatchArbitraryBitMaskBuilder ipv6MatchArbitraryBitMaskBuilder = data.getIpv6MatchArbitraryBitMaskBuilder();
Ipv6Src ipv6Src = source.getIpv6Src();
if (ipv6Src != null) {
byte[] mask = ipv6Src.getMask();
if (mask != null && IpConversionUtil.isIpv6ArbitraryBitMask(mask)) {
if (ipv6MatchBuilder.getIpv6Destination() != null) {
Ipv6Prefix ipv6PrefixDestinationAddress = ipv6MatchBuilder.getIpv6Destination();
Ipv6Address ipv6DstAddress = IpConversionUtil.extractIpv6Address(ipv6PrefixDestinationAddress);
Ipv6ArbitraryMask dstIpv6ArbitraryMask = IpConversionUtil.compressedIpv6MaskFormat(IpConversionUtil.extractIpv6AddressMask(ipv6PrefixDestinationAddress));
setDstIpv6MatchArbitraryBitMaskBuilderFields(ipv6MatchArbitraryBitMaskBuilder, dstIpv6ArbitraryMask, IpConversionUtil.compressedIpv6AddressFormat(ipv6DstAddress));
}
Ipv6ArbitraryMask srcIpv6ArbitraryMask = IpConversionUtil.compressedIpv6MaskFormat(IpConversionUtil.createIpv6ArbitraryBitMask(mask));
Ipv6Address stringIpv6SrcAddress = IpConversionUtil.compressedIpv6AddressFormat(ipv6Src.getIpv6Address());
setSrcIpv6MatchArbitraryBitMaskBuilderFields(ipv6MatchArbitraryBitMaskBuilder, srcIpv6ArbitraryMask, stringIpv6SrcAddress);
matchBuilder.setLayer3Match(ipv6MatchArbitraryBitMaskBuilder.build());
} else if (ipv6MatchArbitraryBitMaskBuilder.getIpv6DestinationAddressNoMask() != null) {
/*
TODO Change comments
Case where destination is of type ipv6MatchArbitraryBitMask already exists in Layer3Match,
source which of type ipv6Match needs to be converted to ipv4MatchArbitraryBitMask.
We convert 1::/32 to 1::/FFFF:FFFF::
example:-
<ipv6-source>1::/32</ipv4-source>
<ipv6-destination-address-no-mask>1::1</ipv6-destination-address-no-mask>
<ipv6-destination-arbitrary-bitmask>FFFF::0001</ipv6-destination-arbitrary-bitmask>
after conversion output example:-
<ipv6-source-address-no-mask>1::</ipv6-source-address-no-mask>
<ipv6-source-arbitrary-bitmask>FFFF:FFFF::</ipv6-source-arbitrary-bitmask>
<ipv6-destination-address-no-mask>1::1</ipv6-destination-address-no-mask>
<ipv6-destination-arbitrary-bitmask>FFFF::0001</ipv6-destination-arbitrary-bitmask>
*/
Ipv6ArbitraryMask srcIpv6ArbitraryMask = IpConversionUtil.compressedIpv6MaskFormat(IpConversionUtil.createIpv6ArbitraryBitMask(mask));
Ipv6Address stringIpv6SrcAddress = IpConversionUtil.compressedIpv6AddressFormat(ipv6Src.getIpv6Address());
setSrcIpv6MatchArbitraryBitMaskBuilderFields(ipv6MatchArbitraryBitMaskBuilder, srcIpv6ArbitraryMask, stringIpv6SrcAddress);
matchBuilder.setLayer3Match(ipv6MatchArbitraryBitMaskBuilder.build());
} else {
Ipv6Address stringIpv6SrcAddress = IpConversionUtil.compressedIpv6AddressFormat(ipv6Src.getIpv6Address());
setIpv6MatchBuilderFields(ipv6MatchBuilder, mask, stringIpv6SrcAddress);
matchBuilder.setLayer3Match(ipv6MatchBuilder.build());
}
}
return Optional.of(matchBuilder);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.opendaylight.ipv6.arbitrary.bitmask.fields.rev160224.Ipv6ArbitraryMask 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());
}
Aggregations