use of org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4MatchArbitraryBitMask 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);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4MatchArbitraryBitMask in project openflowplugin by opendaylight.
the class MatchResponseConvertor2Test method testWithMatchEntryWithSrcCidrMaskAndDstArbitraryBitMask.
/**
* Test {@link MatchResponseConvertor#convert(MatchEntriesGrouping, VersionDatapathIdConvertorData)}.
*/
@Test
public void testWithMatchEntryWithSrcCidrMaskAndDstArbitraryBitMask() {
final MatchBuilder builder = new MatchBuilder();
builder.setType(OxmMatchType.class);
final List<MatchEntry> entries = new ArrayList<>();
MatchEntryBuilder entriesBuilder = new MatchEntryBuilder();
entriesBuilder.setOxmClass(OpenflowBasicClass.class);
entriesBuilder.setOxmMatchField(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.Metadata.class);
entriesBuilder.setHasMask(true);
entriesBuilder = new MatchEntryBuilder();
entriesBuilder.setOxmClass(OpenflowBasicClass.class);
entriesBuilder.setOxmMatchField(Ipv4Src.class);
entriesBuilder.setHasMask(true);
final Ipv4SrcCaseBuilder ipv4SrcCaseBuilder = new Ipv4SrcCaseBuilder();
final Ipv4SrcBuilder ipv4SrcBuilder = new Ipv4SrcBuilder();
ipv4SrcBuilder.setIpv4Address(new Ipv4Address("10.1.1.1"));
ipv4SrcBuilder.setMask(new byte[] { (byte) 255, (byte) 255, (byte) 255, 0 });
ipv4SrcCaseBuilder.setIpv4Src(ipv4SrcBuilder.build());
entriesBuilder.setMatchEntryValue(ipv4SrcCaseBuilder.build());
entries.add(entriesBuilder.build());
entriesBuilder = new MatchEntryBuilder();
entriesBuilder.setOxmClass(OpenflowBasicClass.class);
entriesBuilder.setOxmMatchField(Ipv4Dst.class);
entriesBuilder.setHasMask(true);
final Ipv4DstCaseBuilder ipv4DstCaseBuilder = new Ipv4DstCaseBuilder();
final Ipv4DstBuilder ipv4AddressBuilder = new Ipv4DstBuilder();
ipv4AddressBuilder.setIpv4Address(new Ipv4Address("10.0.1.1"));
ipv4AddressBuilder.setMask(new byte[] { (byte) 255, 0, (byte) 240, 0 });
ipv4DstCaseBuilder.setIpv4Dst(ipv4AddressBuilder.build());
entriesBuilder.setMatchEntryValue(ipv4DstCaseBuilder.build());
entries.add(entriesBuilder.build());
builder.setMatchEntry(entries);
final Match match = builder.build();
final VersionDatapathIdConvertorData datapathIdConvertorData = new VersionDatapathIdConvertorData(OFConstants.OFP_VERSION_1_3);
datapathIdConvertorData.setDatapathId(new BigInteger("42"));
final org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder salMatch = convert(match, datapathIdConvertorData);
final org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match builtMatch = salMatch.build();
final Ipv4MatchArbitraryBitMask ipv4MatchArbitraryBitMask = (Ipv4MatchArbitraryBitMask) builtMatch.getLayer3Match();
Assert.assertEquals("Wrong ipv4 src address", "10.1.1.1", ipv4MatchArbitraryBitMask.getIpv4SourceAddressNoMask().getValue());
Assert.assertEquals("Wrong ipv4 dst address", "10.0.1.1", ipv4MatchArbitraryBitMask.getIpv4DestinationAddressNoMask().getValue());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4MatchArbitraryBitMask in project openflowplugin by opendaylight.
the class MatchResponseConvertor2Test method testWithMatchEntryWithSrcArbitraryBitMaskAndDstCidrMask.
/**
* Test {@link MatchResponseConvertor#convert(MatchEntriesGrouping, VersionDatapathIdConvertorData)}.
*/
@Test
public void testWithMatchEntryWithSrcArbitraryBitMaskAndDstCidrMask() {
final MatchBuilder builder = new MatchBuilder();
builder.setType(OxmMatchType.class);
final List<MatchEntry> entries = new ArrayList<>();
MatchEntryBuilder entriesBuilder = new MatchEntryBuilder();
entriesBuilder.setOxmClass(OpenflowBasicClass.class);
entriesBuilder.setOxmMatchField(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.Metadata.class);
entriesBuilder.setHasMask(true);
entriesBuilder = new MatchEntryBuilder();
entriesBuilder.setOxmClass(OpenflowBasicClass.class);
entriesBuilder.setOxmMatchField(Ipv4Src.class);
entriesBuilder.setHasMask(true);
final Ipv4SrcCaseBuilder ipv4SrcCaseBuilder = new Ipv4SrcCaseBuilder();
final Ipv4SrcBuilder ipv4SrcBuilder = new Ipv4SrcBuilder();
ipv4SrcBuilder.setIpv4Address(new Ipv4Address("10.1.1.1"));
ipv4SrcBuilder.setMask(new byte[] { (byte) 255, (byte) 0, (byte) 255, 0 });
ipv4SrcCaseBuilder.setIpv4Src(ipv4SrcBuilder.build());
entriesBuilder.setMatchEntryValue(ipv4SrcCaseBuilder.build());
entries.add(entriesBuilder.build());
entriesBuilder = new MatchEntryBuilder();
entriesBuilder.setOxmClass(OpenflowBasicClass.class);
entriesBuilder.setOxmMatchField(Ipv4Dst.class);
entriesBuilder.setHasMask(true);
final Ipv4DstCaseBuilder ipv4DstCaseBuilder = new Ipv4DstCaseBuilder();
final Ipv4DstBuilder ipv4AddressBuilder = new Ipv4DstBuilder();
ipv4AddressBuilder.setIpv4Address(new Ipv4Address("10.0.1.1"));
ipv4AddressBuilder.setMask(new byte[] { (byte) 255, (byte) 255, (byte) 240, 0 });
ipv4DstCaseBuilder.setIpv4Dst(ipv4AddressBuilder.build());
entriesBuilder.setMatchEntryValue(ipv4DstCaseBuilder.build());
entries.add(entriesBuilder.build());
builder.setMatchEntry(entries);
final Match match = builder.build();
final VersionDatapathIdConvertorData datapathIdConvertorData = new VersionDatapathIdConvertorData(OFConstants.OFP_VERSION_1_3);
datapathIdConvertorData.setDatapathId(new BigInteger("42"));
final org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder salMatch = convert(match, datapathIdConvertorData);
final org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match builtMatch = salMatch.build();
final Ipv4MatchArbitraryBitMask ipv4MatchArbitraryBitMask = (Ipv4MatchArbitraryBitMask) builtMatch.getLayer3Match();
Assert.assertEquals("Wrong ipv4 src address", "10.1.1.1", ipv4MatchArbitraryBitMask.getIpv4SourceAddressNoMask().getValue());
Assert.assertEquals("Wrong ipv4 dst address", "10.0.1.1", ipv4MatchArbitraryBitMask.getIpv4DestinationAddressNoMask().getValue());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4MatchArbitraryBitMask 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);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4MatchArbitraryBitMask 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);
}
Aggregations