Search in sources :

Example 1 with Ipv6ArbitraryMask

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));
    });
}
Also used : Ipv6ArbitraryMask(org.opendaylight.yang.gen.v1.urn.opendaylight.opendaylight.ipv6.arbitrary.bitmask.fields.rev160224.Ipv6ArbitraryMask) Ipv6MatchArbitraryBitMaskBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv6MatchArbitraryBitMaskBuilder) MatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder) Ipv6Address(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Address) Match(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match) Test(org.junit.Test)

Example 2 with Ipv6ArbitraryMask

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);
    }
}
Also used : Ipv6ArbitraryMask(org.opendaylight.yang.gen.v1.urn.opendaylight.opendaylight.ipv6.arbitrary.bitmask.fields.rev160224.Ipv6ArbitraryMask) Test(org.junit.Test)

Example 3 with Ipv6ArbitraryMask

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");
}
Also used : Ipv6ArbitraryMask(org.opendaylight.yang.gen.v1.urn.opendaylight.opendaylight.ipv6.arbitrary.bitmask.fields.rev160224.Ipv6ArbitraryMask) Test(org.junit.Test)

Example 4 with Ipv6ArbitraryMask

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);
}
Also used : Ipv6Src(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.ipv6.src._case.Ipv6Src) Ipv6ArbitraryMask(org.opendaylight.yang.gen.v1.urn.opendaylight.opendaylight.ipv6.arbitrary.bitmask.fields.rev160224.Ipv6ArbitraryMask) Ipv6MatchArbitraryBitMaskBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv6MatchArbitraryBitMaskBuilder) MatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder) Ipv6MatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv6MatchBuilder) Ipv6MatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv6MatchBuilder) Ipv6Address(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Address) Ipv6Prefix(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix)

Example 5 with Ipv6ArbitraryMask

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());
}
Also used : UnknownHostException(java.net.UnknownHostException) Ipv6ArbitraryMask(org.opendaylight.yang.gen.v1.urn.opendaylight.opendaylight.ipv6.arbitrary.bitmask.fields.rev160224.Ipv6ArbitraryMask) BitSet(java.util.BitSet) InetAddress(java.net.InetAddress) Nullable(javax.annotation.Nullable)

Aggregations

Ipv6ArbitraryMask (org.opendaylight.yang.gen.v1.urn.opendaylight.opendaylight.ipv6.arbitrary.bitmask.fields.rev160224.Ipv6ArbitraryMask)13 Test (org.junit.Test)9 Ipv6Address (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Address)7 MatchBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder)6 Ipv6MatchArbitraryBitMaskBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv6MatchArbitraryBitMaskBuilder)6 Ipv6Prefix (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix)5 Ipv6MatchBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv6MatchBuilder)4 Match (org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match)2 EthernetMatchBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatchBuilder)2 ArpMatchBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.ArpMatchBuilder)2 Ipv4MatchBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4MatchBuilder)2 TunnelIpv4MatchBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.TunnelIpv4MatchBuilder)2 MatchEntry (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry)2 InetAddress (java.net.InetAddress)1 UnknownHostException (java.net.UnknownHostException)1 ArrayList (java.util.ArrayList)1 BitSet (java.util.BitSet)1 List (java.util.List)1 Nullable (javax.annotation.Nullable)1 VersionConvertorData (org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionConvertorData)1