Search in sources :

Example 1 with DottedQuad

use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DottedQuad in project openflowplugin by opendaylight.

the class OfToSalIpv4SrcCase method process.

@Override
public Optional<MatchBuilder> process(@Nonnull Ipv4SrcCase source, MatchResponseConvertorData data, ConvertorExecutor convertorExecutor) {
    final MatchBuilder matchBuilder = data.getMatchBuilder();
    final Ipv4MatchBuilder ipv4MatchBuilder = data.getIpv4MatchBuilder();
    final Ipv4MatchArbitraryBitMaskBuilder ipv4MatchArbitraryBitMaskBuilder = data.getIpv4MatchArbitraryBitMaskBuilder();
    Ipv4Src ipv4Address = source.getIpv4Src();
    if (ipv4Address != null) {
        byte[] mask = ipv4Address.getMask();
        if (mask != null && IpConversionUtil.isArbitraryBitMask(mask)) {
            // Needs to convert ipv4dst to ipv4MatchArbitrary.
            if (ipv4MatchBuilder.getIpv4Destination() != null) {
                Ipv4Prefix ipv4PrefixDestinationAddress = ipv4MatchBuilder.getIpv4Destination();
                Ipv4Address ipv4DstAddress = IpConversionUtil.extractIpv4Address(ipv4PrefixDestinationAddress);
                DottedQuad dstDottedQuadMask = IpConversionUtil.extractIpv4AddressMask(ipv4PrefixDestinationAddress);
                setDstIpv4MatchArbitraryBitMaskBuilderFields(ipv4MatchArbitraryBitMaskBuilder, dstDottedQuadMask, ipv4DstAddress.getValue());
            }
            DottedQuad srcDottedQuadMask = IpConversionUtil.createArbitraryBitMask(mask);
            String stringIpv4SrcAddress = ipv4Address.getIpv4Address().getValue();
            setSrcIpv4MatchArbitraryBitMaskBuilderFields(ipv4MatchArbitraryBitMaskBuilder, srcDottedQuadMask, stringIpv4SrcAddress);
            matchBuilder.setLayer3Match(ipv4MatchArbitraryBitMaskBuilder.build());
        } else if (ipv4MatchArbitraryBitMaskBuilder.getIpv4DestinationAddressNoMask() != null) {
            /*
                Case where destination is of type ipv4MatchArbitraryBitMask already exists in Layer3Match,
                source which of type ipv4Match needs to be converted to ipv4MatchArbitraryBitMask.
                We convert 36.36.36.0/24 to 36.36.0/255.255.255.0
                expected output example:-
                <ipv4-destination>36.36.36.0/24</ipv4-destination>
                <ipv4-source-address-no-mask>36.36.36.0</ipv4-source-address-no-mask>
                <ipv4-source-arbitrary-bitmask>255.0.255.0</ipv4-source-arbitrary-bitmask>
                after conversion output example:-
                <ipv4-destination-address-no-mask>36.36.36.0</ipv4-destination-address-no-mask>
                <ipv4-destination-arbitrary-bitmask>255.255.255.0</ipv4-destination-arbitrary-bitmask>
                <ipv4-source-address-no-mask>36.36.36.0</ipv4-source-address-no-mask>
                <ipv4-source-arbitrary-bitmask>255.0.255.0</ipv4-source-arbitrary-bitmask>
                */
            DottedQuad srcDottedQuadMask = IpConversionUtil.createArbitraryBitMask(mask);
            String stringIpv4SrcAddress = ipv4Address.getIpv4Address().getValue();
            setSrcIpv4MatchArbitraryBitMaskBuilderFields(ipv4MatchArbitraryBitMaskBuilder, srcDottedQuadMask, stringIpv4SrcAddress);
            matchBuilder.setLayer3Match(ipv4MatchArbitraryBitMaskBuilder.build());
        } else {
            String stringIpv4SrcAddress = ipv4Address.getIpv4Address().getValue();
            setIpv4MatchBuilderFields(ipv4MatchBuilder, mask, stringIpv4SrcAddress);
            matchBuilder.setLayer3Match(ipv4MatchBuilder.build());
        }
    }
    return Optional.of(matchBuilder);
}
Also used : Ipv4MatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4MatchBuilder) Ipv4Src(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.ipv4.src._case.Ipv4Src) Ipv4MatchArbitraryBitMaskBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4MatchArbitraryBitMaskBuilder) DottedQuad(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DottedQuad) MatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder) Ipv4MatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4MatchBuilder) Ipv4Prefix(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix) Ipv4Address(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address)

Example 2 with DottedQuad

use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DottedQuad in project openflowplugin by opendaylight.

the class Ipv4ArbitraryBitMaskDestinationEntrySerializerTest method testSerialize.

@Test
public void testSerialize() throws Exception {
    final Ipv4Address ipv4Address = new Ipv4Address("192.168.10.0");
    final DottedQuad ipv4mask = new DottedQuad("255.255.255.0");
    final Match ipv4abmMatch = new MatchBuilder().setLayer3Match(new Ipv4MatchArbitraryBitMaskBuilder().setIpv4DestinationAddressNoMask(ipv4Address).setIpv4DestinationArbitraryBitmask(ipv4mask).build()).build();
    assertMatch(ipv4abmMatch, true, (out) -> {
        byte[] address = new byte[4];
        out.readBytes(address);
        assertArrayEquals(address, new byte[] { (byte) 192, (byte) 168, 10, 0 });
        byte[] mask = new byte[4];
        out.readBytes(mask);
        assertArrayEquals(mask, new byte[] { (byte) 255, (byte) 255, (byte) 255, 0 });
    });
    final Match ipv4abmMatchNoMask = new MatchBuilder().setLayer3Match(new Ipv4MatchArbitraryBitMaskBuilder().setIpv4DestinationAddressNoMask(ipv4Address).build()).build();
    assertMatch(ipv4abmMatchNoMask, false, (out) -> {
        byte[] address = new byte[4];
        out.readBytes(address);
        assertArrayEquals(address, new byte[] { (byte) 192, (byte) 168, 10, 0 });
    });
}
Also used : Ipv4MatchArbitraryBitMaskBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4MatchArbitraryBitMaskBuilder) DottedQuad(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DottedQuad) MatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder) Ipv4Address(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address) Match(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match) Test(org.junit.Test)

Example 3 with DottedQuad

use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DottedQuad in project openflowplugin by opendaylight.

the class SalToOfIpv4MatchArbitraryBitMaskCase method process.

@Override
public Optional<List<MatchEntry>> process(@Nonnull Ipv4MatchArbitraryBitMask source, VersionConvertorData data, ConvertorExecutor convertorExecutor) {
    List<MatchEntry> result = new ArrayList<>();
    if (source.getIpv4SourceAddressNoMask() != null) {
        MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder();
        matchEntryBuilder.setOxmClass(OpenflowBasicClass.class);
        matchEntryBuilder.setOxmMatchField(Ipv4Src.class);
        Ipv4SrcBuilder ipv4SrcBuilder = new Ipv4SrcBuilder();
        ipv4SrcBuilder.setIpv4Address(source.getIpv4SourceAddressNoMask());
        DottedQuad sourceArbitrarySubNetMask = source.getIpv4SourceArbitraryBitmask();
        boolean hasMask = false;
        if (sourceArbitrarySubNetMask != null) {
            byte[] maskByteArray = IpConversionUtil.convertArbitraryMaskToByteArray(sourceArbitrarySubNetMask);
            if (maskByteArray != null) {
                ipv4SrcBuilder.setMask(maskByteArray);
                hasMask = true;
            }
        }
        matchEntryBuilder.setHasMask(hasMask);
        Ipv4SrcCaseBuilder ipv4SrcCaseBuilder = new Ipv4SrcCaseBuilder();
        ipv4SrcCaseBuilder.setIpv4Src(ipv4SrcBuilder.build());
        matchEntryBuilder.setMatchEntryValue(ipv4SrcCaseBuilder.build());
        result.add(matchEntryBuilder.build());
    }
    if (source.getIpv4DestinationAddressNoMask() != null) {
        MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder();
        matchEntryBuilder.setOxmClass(OpenflowBasicClass.class);
        matchEntryBuilder.setOxmMatchField(Ipv4Dst.class);
        Ipv4DstBuilder ipv4DstBuilder = new Ipv4DstBuilder();
        ipv4DstBuilder.setIpv4Address(source.getIpv4DestinationAddressNoMask());
        DottedQuad destArbitrarySubNetMask = source.getIpv4DestinationArbitraryBitmask();
        boolean hasMask = false;
        if (destArbitrarySubNetMask != null) {
            byte[] maskByteArray = IpConversionUtil.convertArbitraryMaskToByteArray(destArbitrarySubNetMask);
            if (maskByteArray != null) {
                ipv4DstBuilder.setMask(maskByteArray);
                hasMask = true;
            }
        }
        matchEntryBuilder.setHasMask(hasMask);
        Ipv4DstCaseBuilder ipv4DstCaseBuilder = new Ipv4DstCaseBuilder();
        ipv4DstCaseBuilder.setIpv4Dst(ipv4DstBuilder.build());
        matchEntryBuilder.setMatchEntryValue(ipv4DstCaseBuilder.build());
        result.add(matchEntryBuilder.build());
    }
    return Optional.of(result);
}
Also used : Ipv4SrcCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.Ipv4SrcCaseBuilder) MatchEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry) MatchEntryBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntryBuilder) Ipv4DstBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.ipv4.dst._case.Ipv4DstBuilder) Ipv4DstCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.Ipv4DstCaseBuilder) ArrayList(java.util.ArrayList) DottedQuad(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DottedQuad) Ipv4SrcBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.ipv4.src._case.Ipv4SrcBuilder)

Example 4 with DottedQuad

use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DottedQuad in project openflowplugin by opendaylight.

the class OfToSalIpv4DstCase method process.

@Override
public Optional<MatchBuilder> process(@Nonnull Ipv4DstCase source, MatchResponseConvertorData data, ConvertorExecutor convertorExecutor) {
    final MatchBuilder matchBuilder = data.getMatchBuilder();
    final Ipv4MatchBuilder ipv4MatchBuilder = data.getIpv4MatchBuilder();
    final Ipv4MatchArbitraryBitMaskBuilder ipv4MatchArbitraryBitMaskBuilder = data.getIpv4MatchArbitraryBitMaskBuilder();
    Ipv4Dst ipv4Address = source.getIpv4Dst();
    if (ipv4Address != null) {
        byte[] mask = ipv4Address.getMask();
        if (mask != null && IpConversionUtil.isArbitraryBitMask(mask)) {
            // Needs to convert ipv4src to ipv4MatchArbitrary.
            if (ipv4MatchBuilder.getIpv4Source() != null) {
                Ipv4Prefix ipv4PrefixSourceAddress = ipv4MatchBuilder.getIpv4Source();
                Ipv4Address ipv4SourceAddress = IpConversionUtil.extractIpv4Address(ipv4PrefixSourceAddress);
                DottedQuad srcDottedQuad = IpConversionUtil.extractIpv4AddressMask(ipv4PrefixSourceAddress);
                setSrcIpv4MatchArbitraryBitMaskBuilderFields(ipv4MatchArbitraryBitMaskBuilder, srcDottedQuad, ipv4SourceAddress.getValue());
            }
            DottedQuad dstDottedQuadMask = IpConversionUtil.createArbitraryBitMask(mask);
            String stringIpv4DstAddress = ipv4Address.getIpv4Address().getValue();
            setDstIpv4MatchArbitraryBitMaskBuilderFields(ipv4MatchArbitraryBitMaskBuilder, dstDottedQuadMask, stringIpv4DstAddress);
            matchBuilder.setLayer3Match(ipv4MatchArbitraryBitMaskBuilder.build());
        } else if (ipv4MatchArbitraryBitMaskBuilder.getIpv4SourceAddressNoMask() != null) {
            /*
                        Case where source is of type ipv4MatchArbitraryBitMask already exists in Layer3Match,
                        destination which of type ipv4Match needs to be converted to ipv4MatchArbitraryBitMask.
                        We convert 36.36.36.0/24 to 36.36.0/255.255.255.0
                        expected output example:-
                        <ipv4-source>36.36.36.0/24</ipv4-source>
                        <ipv4-destination-address-no-mask>36.36.36.0</ipv4-destination-address-no-mask>
                        <ipv4-destination-arbitrary-bitmask>255.0.255.0</ipv4-destination-arbitrary-bitmask>
                        after conversion output example:-
                        <ipv4-source-address-no-mask>36.36.36.0</ipv4-source-address-no-mask>
                        <ipv4-source-arbitrary-bitmask>255.255.255.0</ipv4-source-arbitrary-bitmask>
                        <ipv4-destination-address-no-mask>36.36.36.0</ipv4-destination-address-no-mask>
                        <ipv4-destination-arbitrary-bitmask>255.0.255.0</ipv4-destination-arbitrary-bitmask>
                        */
            DottedQuad dstDottedQuadMask = IpConversionUtil.createArbitraryBitMask(mask);
            String stringIpv4DstAddress = ipv4Address.getIpv4Address().getValue();
            setDstIpv4MatchArbitraryBitMaskBuilderFields(ipv4MatchArbitraryBitMaskBuilder, dstDottedQuadMask, stringIpv4DstAddress);
            matchBuilder.setLayer3Match(ipv4MatchArbitraryBitMaskBuilder.build());
        } else {
            String ipv4PrefixStr = ipv4Address.getIpv4Address().getValue();
            setIpv4MatchBuilderFields(ipv4MatchBuilder, mask, ipv4PrefixStr);
            matchBuilder.setLayer3Match(ipv4MatchBuilder.build());
        }
    }
    return Optional.of(matchBuilder);
}
Also used : Ipv4MatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4MatchBuilder) Ipv4MatchArbitraryBitMaskBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4MatchArbitraryBitMaskBuilder) DottedQuad(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DottedQuad) MatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder) Ipv4MatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4MatchBuilder) Ipv4Dst(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.ipv4.dst._case.Ipv4Dst) Ipv4Prefix(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix) Ipv4Address(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address)

Example 5 with DottedQuad

use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DottedQuad in project openflowplugin by opendaylight.

the class Ipv4ArbitraryBitMaskSourceEntrySerializerTest method testSerialize.

@Test
public void testSerialize() throws Exception {
    final Ipv4Address ipv4Address = new Ipv4Address("192.168.10.0");
    final DottedQuad ipv4mask = new DottedQuad("255.255.255.0");
    final Match ipv4abmMatch = new MatchBuilder().setLayer3Match(new Ipv4MatchArbitraryBitMaskBuilder().setIpv4SourceAddressNoMask(ipv4Address).setIpv4SourceArbitraryBitmask(ipv4mask).build()).build();
    assertMatch(ipv4abmMatch, true, (out) -> {
        byte[] address = new byte[4];
        out.readBytes(address);
        assertArrayEquals(address, new byte[] { (byte) 192, (byte) 168, 10, 0 });
        byte[] mask = new byte[4];
        out.readBytes(mask);
        assertArrayEquals(mask, new byte[] { (byte) 255, (byte) 255, (byte) 255, 0 });
    });
    final Match ipv4abmMatchNoMask = new MatchBuilder().setLayer3Match(new Ipv4MatchArbitraryBitMaskBuilder().setIpv4SourceAddressNoMask(ipv4Address).build()).build();
    assertMatch(ipv4abmMatchNoMask, false, (out) -> {
        byte[] address = new byte[4];
        out.readBytes(address);
        assertArrayEquals(address, new byte[] { (byte) 192, (byte) 168, 10, 0 });
    });
}
Also used : Ipv4MatchArbitraryBitMaskBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4MatchArbitraryBitMaskBuilder) DottedQuad(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DottedQuad) MatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder) Ipv4Address(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address) Match(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match) Test(org.junit.Test)

Aggregations

DottedQuad (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DottedQuad)11 Test (org.junit.Test)7 Ipv4Address (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address)7 MatchBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder)6 Ipv4MatchArbitraryBitMaskBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4MatchArbitraryBitMaskBuilder)6 Ipv4Prefix (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix)5 Ipv4MatchBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4MatchBuilder)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 Ipv6MatchBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv6MatchBuilder)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 BigInteger (java.math.BigInteger)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 VersionConvertorData (org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionConvertorData)1 Match (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match)1 Icmpv4MatchBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Icmpv4MatchBuilder)1 Icmpv6MatchBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Icmpv6MatchBuilder)1