From: Robert Varga Date: Tue, 3 Jun 2014 21:53:29 +0000 (+0200) Subject: Optimize string splitting by using Splitter class X-Git-Tag: release/helium~162 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=0326de0142122b44aef3d4b2ed94e64ab2378dbb;p=openflowplugin.git Optimize string splitting by using Splitter class Instead of performing costli String.split() operation, instantiate a shared Splitter and use it to split the string. Requires slight alterations to logic, but those are rather obvious. Change-Id: Icec3c4588e062373c090b3479635a93428f278f1 Signed-off-by: Robert Varga --- diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/ActionSetNwDstConvertorImpl.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/ActionSetNwDstConvertorImpl.java index ae271048ba..ade7843430 100644 --- a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/ActionSetNwDstConvertorImpl.java +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/ActionSetNwDstConvertorImpl.java @@ -18,22 +18,23 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.addr import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.address.address.Ipv4; import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.address.address.Ipv6; +import com.google.common.base.Splitter; + /** * Utility class for converting a MD-SAL action subelement into the OF subelement */ public class ActionSetNwDstConvertorImpl implements Convertor { - - private static final String PREFIX_SEPARATOR = "/"; - + private static final Splitter PREFIX_SPLITTER = Splitter.on('/'); + @Override - public Object convert(SetNwDstActionCase source, BigInteger datapathid) { + public Object convert(final SetNwDstActionCase source, final BigInteger datapathid) { Address address = source.getSetNwDstAction().getAddress(); if (address instanceof Ipv4) { - String[] addressParts = ((Ipv4) address).getIpv4Address().getValue().split(PREFIX_SEPARATOR); - return new Ipv4Address(addressParts[0]); + Iterable addressParts = PREFIX_SPLITTER.split(((Ipv4) address).getIpv4Address().getValue()); + return new Ipv4Address(addressParts.iterator().next()); } else if (address instanceof Ipv6) { - String[] addressParts = ((Ipv6) address).getIpv6Address().getValue().split(PREFIX_SEPARATOR); - return new Ipv6Address(addressParts[0]); + Iterable addressParts = PREFIX_SPLITTER.split(((Ipv6) address).getIpv6Address().getValue()); + return new Ipv6Address(addressParts.iterator().next()); } else { throw new IllegalArgumentException("Address is not supported: "+address.getClass().getName()); } diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/ActionSetNwSrcConvertorImpl.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/ActionSetNwSrcConvertorImpl.java index bc655a713f..b3b0cdb26e 100644 --- a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/ActionSetNwSrcConvertorImpl.java +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/ActionSetNwSrcConvertorImpl.java @@ -18,22 +18,24 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.addr import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.address.address.Ipv4; import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.address.address.Ipv6; +import com.google.common.base.Splitter; + /** * Utility class for converting a MD-SAL action subelement into the OF subelement */ public class ActionSetNwSrcConvertorImpl implements Convertor { - - private static final String PREFIX_SEPARATOR = "/"; - + + private static final Splitter PREFIX_SPLITTER = Splitter.on('/'); + @Override - public Object convert(SetNwSrcActionCase source, BigInteger datapathid) { + public Object convert(final SetNwSrcActionCase source, final BigInteger datapathid) { Address address = source.getSetNwSrcAction().getAddress(); if (address instanceof Ipv4) { - String[] addressParts = ((Ipv4) address).getIpv4Address().getValue().split(PREFIX_SEPARATOR); - return new Ipv4Address(addressParts[0]); + Iterable addressParts = PREFIX_SPLITTER.split(((Ipv4) address).getIpv4Address().getValue()); + return new Ipv4Address(addressParts.iterator().next()); } else if (address instanceof Ipv6) { - String[] addressParts = ((Ipv6) address).getIpv6Address().getValue().split(PREFIX_SEPARATOR); - return new Ipv6Address(addressParts[0]); + Iterable addressParts = PREFIX_SPLITTER.split(((Ipv6) address).getIpv6Address().getValue()); + return new Ipv6Address(addressParts.iterator().next()); } else { throw new IllegalArgumentException("Address is not supported: "+address.getClass().getName()); } diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/match/MatchConvertorImpl.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/match/MatchConvertorImpl.java index a08f28d20b..4d3d3d7b13 100644 --- a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/match/MatchConvertorImpl.java +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/match/MatchConvertorImpl.java @@ -11,6 +11,7 @@ package org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.match; import java.math.BigInteger; import java.nio.ByteBuffer; import java.util.ArrayList; +import java.util.Iterator; import java.util.List; import org.opendaylight.openflowplugin.openflow.md.OFConstants; @@ -173,12 +174,15 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm. import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import com.google.common.base.Splitter; + /** * Utility class for converting a MD-SAL Flow into the OF flow mod */ public class MatchConvertorImpl implements MatchConvertor> { private static final Logger logger = LoggerFactory.getLogger(MatchConvertorImpl.class); static final String PREFIX_SEPARATOR = "/"; + static final Splitter PREFIX_SPLITTER = Splitter.on('/'); private static final byte[] VLAN_VID_MASK = new byte[] { 16, 0 }; private static final short PROTO_TCP = 6; private static final short PROTO_UDP = 17; @@ -186,7 +190,7 @@ public class MatchConvertorImpl implements MatchConvertor> { @Override public List convert( - org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match match, BigInteger datapathid) { + final org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match match, final BigInteger datapathid) { List matchEntriesList = new ArrayList<>(); if (match.getInPort() != null) { @@ -410,7 +414,7 @@ public class MatchConvertorImpl implements MatchConvertor> { * @return * @author avishnoi@in.ibm.com */ - public static Match fromOFMatchV10ToSALMatch(MatchV10 swMatch, BigInteger datapathid) { + public static Match fromOFMatchV10ToSALMatch(final MatchV10 swMatch, final BigInteger datapathid) { MatchBuilder matchBuilder = new MatchBuilder(); EthernetMatchBuilder ethMatchBuilder = new EthernetMatchBuilder(); VlanMatchBuilder vlanMatchBuilder = new VlanMatchBuilder(); @@ -478,31 +482,37 @@ public class MatchConvertorImpl implements MatchConvertor> { } if (!swMatch.getWildcards().isNWPROTO().booleanValue() && swMatch.getNwProto() == PROTO_TCP) { TcpMatchBuilder tcpMatchBuilder = new TcpMatchBuilder(); - if (!swMatch.getWildcards().isTPSRC().booleanValue() && swMatch.getTpSrc() != null) + if (!swMatch.getWildcards().isTPSRC().booleanValue() && swMatch.getTpSrc() != null) { tcpMatchBuilder .setTcpSourcePort(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber( swMatch.getTpSrc())); - if (!swMatch.getWildcards().isTPDST().booleanValue() && swMatch.getTpDst() != null) + } + if (!swMatch.getWildcards().isTPDST().booleanValue() && swMatch.getTpDst() != null) { tcpMatchBuilder .setTcpDestinationPort(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber( swMatch.getTpDst())); + } - if (!swMatch.getWildcards().isTPSRC().booleanValue() || !swMatch.getWildcards().isTPDST().booleanValue()) + if (!swMatch.getWildcards().isTPSRC().booleanValue() || !swMatch.getWildcards().isTPDST().booleanValue()) { matchBuilder.setLayer4Match(tcpMatchBuilder.build()); + } } if (!swMatch.getWildcards().isNWPROTO().booleanValue() && swMatch.getNwProto() == PROTO_UDP) { UdpMatchBuilder udpMatchBuilder = new UdpMatchBuilder(); - if (!swMatch.getWildcards().isTPSRC().booleanValue() && swMatch.getTpSrc() != null) + if (!swMatch.getWildcards().isTPSRC().booleanValue() && swMatch.getTpSrc() != null) { udpMatchBuilder .setUdpSourcePort(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber( swMatch.getTpSrc())); - if (!swMatch.getWildcards().isTPDST().booleanValue() && swMatch.getTpDst() != null) + } + if (!swMatch.getWildcards().isTPDST().booleanValue() && swMatch.getTpDst() != null) { udpMatchBuilder .setUdpDestinationPort(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber( swMatch.getTpDst())); + } - if (!swMatch.getWildcards().isTPSRC().booleanValue() || !swMatch.getWildcards().isTPDST().booleanValue()) + if (!swMatch.getWildcards().isTPSRC().booleanValue() || !swMatch.getWildcards().isTPDST().booleanValue()) { matchBuilder.setLayer4Match(udpMatchBuilder.build()); + } } if (!swMatch.getWildcards().isNWTOS().booleanValue() && swMatch.getNwTos() != null) { // DSCP default value is 0 from the library but controller side it @@ -526,8 +536,8 @@ public class MatchConvertorImpl implements MatchConvertor> { * @author avishnoi@in.ibm.com */ public static Match fromOFMatchToSALMatch( - org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.match.grouping.Match swMatch, - BigInteger datapathid) { + final org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.match.grouping.Match swMatch, + final BigInteger datapathid) { MatchBuilder matchBuilder = new MatchBuilder(); EthernetMatchBuilder ethMatchBuilder = new EthernetMatchBuilder(); @@ -704,7 +714,7 @@ public class MatchConvertorImpl implements MatchConvertor> { } ipv4PrefixStr += PREFIX_SEPARATOR + (32-shiftCount); }else{ - //Openflow Spec : 1.3.2 + //Openflow Spec : 1.3.2 //An all-one-bits oxm_mask is equivalent to specifying 0 for oxm_hasmask and omitting oxm_mask. // So when user specify 32 as a mast, switch omit that mast and we get null as a mask in flow // statistics response. @@ -880,7 +890,7 @@ public class MatchConvertorImpl implements MatchConvertor> { return matchBuilder.build(); } - private static MatchEntries toOfMplsPbb(Pbb pbb) { + private static MatchEntries toOfMplsPbb(final Pbb pbb) { MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder(); boolean hasmask = false; matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class); @@ -896,7 +906,7 @@ public class MatchConvertorImpl implements MatchConvertor> { return matchEntriesBuilder.build(); } - private static MatchEntries toOfMplsTc(Short mplsTc) { + private static MatchEntries toOfMplsTc(final Short mplsTc) { MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder(); matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class); matchEntriesBuilder.setHasMask(false); @@ -907,7 +917,7 @@ public class MatchConvertorImpl implements MatchConvertor> { return matchEntriesBuilder.build(); } - private static MatchEntries toOfMplsBos(Short mplsBos) { + private static MatchEntries toOfMplsBos(final Short mplsBos) { MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder(); matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class); matchEntriesBuilder.setHasMask(false); @@ -922,7 +932,7 @@ public class MatchConvertorImpl implements MatchConvertor> { return matchEntriesBuilder.build(); } - private static MatchEntries toOfMplsLabel(Long mplsLabel) { + private static MatchEntries toOfMplsLabel(final Long mplsLabel) { MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder(); matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class); matchEntriesBuilder.setHasMask(false); @@ -933,7 +943,7 @@ public class MatchConvertorImpl implements MatchConvertor> { return matchEntriesBuilder.build(); } - private static MatchEntries toOfIpv6ExtHeader(Ipv6ExtHeader ipv6ExtHeader) { + private static MatchEntries toOfIpv6ExtHeader(final Ipv6ExtHeader ipv6ExtHeader) { MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder(); boolean hasmask = false; matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class); @@ -959,7 +969,7 @@ public class MatchConvertorImpl implements MatchConvertor> { return matchEntriesBuilder.build(); } - private static MatchEntries toOfIpv6FlowLabel(Ipv6Label ipv6Label) { + private static MatchEntries toOfIpv6FlowLabel(final Ipv6Label ipv6Label) { MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder(); boolean hasmask = false; matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class); @@ -975,7 +985,7 @@ public class MatchConvertorImpl implements MatchConvertor> { return matchEntriesBuilder.build(); } - private static MatchEntries toOfPort(Class field, Long portNumber) { + private static MatchEntries toOfPort(final Class field, final Long portNumber) { MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder(); matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class); matchEntriesBuilder.setHasMask(false); @@ -986,8 +996,8 @@ public class MatchConvertorImpl implements MatchConvertor> { return matchEntriesBuilder.build(); } - private static MatchEntries toOfMetadata(Class field, BigInteger metadata, - BigInteger metadataMask) { + private static MatchEntries toOfMetadata(final Class field, final BigInteger metadata, + final BigInteger metadataMask) { MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder(); boolean hasmask = false; matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class); @@ -1002,9 +1012,9 @@ public class MatchConvertorImpl implements MatchConvertor> { return matchEntriesBuilder.build(); } - public static MatchEntries toOfMacAddress(Class field, - org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress macAddress, - org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress mask) { + public static MatchEntries toOfMacAddress(final Class field, + final org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress macAddress, + final org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress mask) { MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder(); boolean hasmask = false; matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class); @@ -1018,7 +1028,7 @@ public class MatchConvertorImpl implements MatchConvertor> { return matchEntriesBuilder.build(); } - private static MatchEntries toOfEthernetType(EthernetType ethernetType) { + private static MatchEntries toOfEthernetType(final EthernetType ethernetType) { MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder(); matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class); matchEntriesBuilder.setHasMask(false); @@ -1029,8 +1039,8 @@ public class MatchConvertorImpl implements MatchConvertor> { return matchEntriesBuilder.build(); } - private static MatchEntries toOfLayer3Port(Class field, - org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber portNumber) { + private static MatchEntries toOfLayer3Port(final Class field, + final org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber portNumber) { MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder(); matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class); matchEntriesBuilder.setHasMask(false); @@ -1041,7 +1051,7 @@ public class MatchConvertorImpl implements MatchConvertor> { return matchEntriesBuilder.build(); } - private static MatchEntries toOfIcmpv4Type(Short icmpv4Type) { + private static MatchEntries toOfIcmpv4Type(final Short icmpv4Type) { MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder(); matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class); matchEntriesBuilder.setHasMask(false); @@ -1052,7 +1062,7 @@ public class MatchConvertorImpl implements MatchConvertor> { return matchEntriesBuilder.build(); } - private static MatchEntries toOfIcmpv4Code(Short icmpv4Code) { + private static MatchEntries toOfIcmpv4Code(final Short icmpv4Code) { MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder(); matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class); matchEntriesBuilder.setHasMask(false); @@ -1063,7 +1073,7 @@ public class MatchConvertorImpl implements MatchConvertor> { return matchEntriesBuilder.build(); } - private static MatchEntries toOfIcmpv6Type(Short icmpv6Type) { + private static MatchEntries toOfIcmpv6Type(final Short icmpv6Type) { MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder(); matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class); matchEntriesBuilder.setHasMask(false); @@ -1074,7 +1084,7 @@ public class MatchConvertorImpl implements MatchConvertor> { return matchEntriesBuilder.build(); } - private static MatchEntries toOfIcmpv6Code(Short icmpv6Code) { + private static MatchEntries toOfIcmpv6Code(final Short icmpv6Code) { MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder(); matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class); matchEntriesBuilder.setHasMask(false); @@ -1085,7 +1095,7 @@ public class MatchConvertorImpl implements MatchConvertor> { return matchEntriesBuilder.build(); } - public static MatchEntries toOfIpv4Prefix(Class field, Ipv4Prefix ipv4Prefix) { + public static MatchEntries toOfIpv4Prefix(final Class field, final Ipv4Prefix ipv4Prefix) { MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder(); matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class); matchEntriesBuilder.setOxmMatchField(field); @@ -1094,7 +1104,7 @@ public class MatchConvertorImpl implements MatchConvertor> { return matchEntriesBuilder.build(); } - private static MatchEntries toOfIpv6Prefix(Class field, Ipv6Prefix ipv6Prefix) { + private static MatchEntries toOfIpv6Prefix(final Class field, final Ipv6Prefix ipv6Prefix) { MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder(); matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class); matchEntriesBuilder.setOxmMatchField(field); @@ -1103,7 +1113,7 @@ public class MatchConvertorImpl implements MatchConvertor> { return matchEntriesBuilder.build(); } - public static MatchEntries toOfIpDscp(Dscp ipDscp) { + public static MatchEntries toOfIpDscp(final Dscp ipDscp) { MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder(); matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class); matchEntriesBuilder.setHasMask(false); @@ -1115,7 +1125,7 @@ public class MatchConvertorImpl implements MatchConvertor> { } public static MatchEntries toOfVlanPcp( - org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanPcp vlanPcp) { + final org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanPcp vlanPcp) { MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder(); matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class); matchEntriesBuilder.setHasMask(false); @@ -1126,7 +1136,7 @@ public class MatchConvertorImpl implements MatchConvertor> { return matchEntriesBuilder.build(); } - private static MatchEntries toOfVlanVid(VlanId vlanId) { + private static MatchEntries toOfVlanVid(final VlanId vlanId) { // TODO: verify MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder(); boolean hasmask = false; @@ -1152,7 +1162,7 @@ public class MatchConvertorImpl implements MatchConvertor> { return matchEntriesBuilder.build(); } - private static MatchEntries toOfIpProto(Short ipProtocol) { + private static MatchEntries toOfIpProto(final Short ipProtocol) { MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder(); matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class); matchEntriesBuilder.setHasMask(false); @@ -1163,7 +1173,7 @@ public class MatchConvertorImpl implements MatchConvertor> { return matchEntriesBuilder.build(); } - private static MatchEntries toOfIpEcn(Short ipEcn) { + private static MatchEntries toOfIpEcn(final Short ipEcn) { MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder(); matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class); matchEntriesBuilder.setHasMask(false); @@ -1174,7 +1184,7 @@ public class MatchConvertorImpl implements MatchConvertor> { return matchEntriesBuilder.build(); } - private static MatchEntries toOfArpOpCode(Integer arpOp) { + private static MatchEntries toOfArpOpCode(final Integer arpOp) { MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder(); matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class); matchEntriesBuilder.setHasMask(false); @@ -1185,7 +1195,7 @@ public class MatchConvertorImpl implements MatchConvertor> { return matchEntriesBuilder.build(); } - private static MatchEntries toOfIpv6Address(Ipv6Address address) { + private static MatchEntries toOfIpv6Address(final Ipv6Address address) { MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder(); matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class); matchEntriesBuilder.setHasMask(false); @@ -1196,21 +1206,22 @@ public class MatchConvertorImpl implements MatchConvertor> { return matchEntriesBuilder.build(); } - private static void addMaskAugmentation(MatchEntriesBuilder builder, byte[] mask) { + private static void addMaskAugmentation(final MatchEntriesBuilder builder, final byte[] mask) { MaskMatchEntryBuilder maskBuilder = new MaskMatchEntryBuilder(); maskBuilder.setMask(mask); builder.addAugmentation(MaskMatchEntry.class, maskBuilder.build()); } - private static boolean addIpv6PrefixAugmentation(MatchEntriesBuilder builder, Ipv6Prefix address) { + private static boolean addIpv6PrefixAugmentation(final MatchEntriesBuilder builder, final Ipv6Prefix address) { boolean hasMask = false; - String[] addressParts = address.getValue().split(PREFIX_SEPARATOR); + Iterator addressParts = PREFIX_SPLITTER.split(address.getValue()).iterator(); + Ipv6Address ipv6Address = new Ipv6Address(addressParts.next()); + Integer prefix = null; - if (addressParts.length == 2) { - prefix = Integer.parseInt(addressParts[1]); + if (addressParts.hasNext()) { + prefix = Integer.parseInt(addressParts.next()); } - Ipv6Address ipv6Address = new Ipv6Address(addressParts[0]); Ipv6AddressMatchEntryBuilder ipv6AddressBuilder = new Ipv6AddressMatchEntryBuilder(); ipv6AddressBuilder.setIpv6Address(ipv6Address); builder.addAugmentation(Ipv6AddressMatchEntry.class, ipv6AddressBuilder.build()); @@ -1221,7 +1232,7 @@ public class MatchConvertorImpl implements MatchConvertor> { return hasMask; } - private static byte[] convertIpv6PrefixToByteArray(int prefix) { + private static byte[] convertIpv6PrefixToByteArray(final int prefix) { // TODO: Temporary fix. Has performance impacts. byte[] mask = new byte[16]; int oneCount = prefix; @@ -1240,7 +1251,7 @@ public class MatchConvertorImpl implements MatchConvertor> { return mask; } - private static void addMetadataAugmentation(MatchEntriesBuilder builder, BigInteger metadata) { + private static void addMetadataAugmentation(final MatchEntriesBuilder builder, final BigInteger metadata) { MetadataMatchEntryBuilder metadataMatchEntry = new MetadataMatchEntryBuilder(); metadataMatchEntry.setMetadata(ByteUtil.convertBigIntegerToNBytes(metadata, OFConstants.SIZE_OF_LONG_IN_BYTES)); builder.addAugmentation(MetadataMatchEntry.class, metadataMatchEntry.build()); @@ -1250,17 +1261,18 @@ public class MatchConvertorImpl implements MatchConvertor> { * @return true if Ipv4Prefix contains prefix (and it is used in mask), * false otherwise */ - private static boolean addIpv4PrefixAugmentation(MatchEntriesBuilder builder, Ipv4Prefix address) { + private static boolean addIpv4PrefixAugmentation(final MatchEntriesBuilder builder, final Ipv4Prefix address) { boolean hasMask = false; - String[] addressParts = address.getValue().split(PREFIX_SEPARATOR); - Integer prefix = null; - if (addressParts.length < 2) { - prefix = 0; + Iterator addressParts = PREFIX_SPLITTER.split(address.getValue()).iterator(); + Ipv4Address ipv4Address = new Ipv4Address(addressParts.next()); + + final int prefix; + if (addressParts.hasNext()) { + prefix = Integer.parseInt(addressParts.next()); } else { - prefix = Integer.parseInt(addressParts[1]); + prefix = 0; } - Ipv4Address ipv4Address = new Ipv4Address(addressParts[0]); Ipv4AddressMatchEntryBuilder ipv4AddressBuilder = new Ipv4AddressMatchEntryBuilder(); ipv4AddressBuilder.setIpv4Address(ipv4Address); builder.addAugmentation(Ipv4AddressMatchEntry.class, ipv4AddressBuilder.build()); @@ -1274,7 +1286,7 @@ public class MatchConvertorImpl implements MatchConvertor> { return hasMask; } - private static void addMacAddressAugmentation(MatchEntriesBuilder builder, MacAddress address) { + private static void addMacAddressAugmentation(final MatchEntriesBuilder builder, final MacAddress address) { MacAddressMatchEntryBuilder macAddress = new MacAddressMatchEntryBuilder(); macAddress.setMacAddress(address); builder.addAugmentation(MacAddressMatchEntry.class, macAddress.build()); @@ -1288,7 +1300,7 @@ public class MatchConvertorImpl implements MatchConvertor> { * @return */ public static SetField ofToSALSetField( - Action action) { + final Action action) { logger.debug("OF SetField match to SAL SetField match converstion begins"); SetFieldBuilder setField = new SetFieldBuilder(); /* diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/match/MatchConvertorV10Impl.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/match/MatchConvertorV10Impl.java index bb0e53e2cc..4821012c71 100644 --- a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/match/MatchConvertorV10Impl.java +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/match/MatchConvertorV10Impl.java @@ -9,6 +9,7 @@ package org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.match; import java.math.BigInteger; +import java.util.Iterator; import org.opendaylight.openflowplugin.openflow.md.util.InventoryDataServiceUtil; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address; @@ -28,10 +29,10 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.matc import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.match.v10.grouping.MatchV10Builder; /** - * + * */ public class MatchConvertorV10Impl implements MatchConvertor { - + /** default MAC */ public static final MacAddress zeroMac = new MacAddress("00:00:00:00:00:00"); /** default IPv4 */ @@ -44,7 +45,7 @@ public class MatchConvertorV10Impl implements MatchConvertor { * @author avishnoi@in.ibm.com */ @Override - public MatchV10 convert(Match match,BigInteger datapathid) { + public MatchV10 convert(final Match match,final BigInteger datapathid) { MatchV10Builder matchBuilder = new MatchV10Builder(); boolean _dLDST = true; boolean _dLSRC = true; @@ -56,7 +57,7 @@ public class MatchConvertorV10Impl implements MatchConvertor { boolean _nWTOS = true; boolean _tPDST = true; boolean _tPSRC = true; - + matchBuilder.setInPort(0); matchBuilder.setDlDst(zeroMac); matchBuilder.setDlSrc(zeroMac); @@ -71,7 +72,7 @@ public class MatchConvertorV10Impl implements MatchConvertor { matchBuilder.setNwTos((short) 0); matchBuilder.setTpSrc(0); matchBuilder.setTpDst(0); - + EthernetMatch ethernetMatch = match.getEthernetMatch(); if(ethernetMatch!= null){ _dLDST = convertEthernetDlDst(matchBuilder, ethernetMatch); @@ -112,12 +113,12 @@ public class MatchConvertorV10Impl implements MatchConvertor { _tPDST = convertL4UdpDstMatch(matchBuilder, udpMatch); } } - + FlowWildcardsV10 wildCards = new FlowWildcardsV10( - _dLDST, _dLSRC, _dLTYPE, _dLVLAN, + _dLDST, _dLSRC, _dLTYPE, _dLVLAN, _dLVLANPCP, _iNPORT, _nWPROTO, _nWTOS, _tPDST, _tPSRC); matchBuilder.setWildcards(wildCards); - + return matchBuilder.build(); } @@ -126,8 +127,8 @@ public class MatchConvertorV10Impl implements MatchConvertor { * @param udpMatch * @return is wildCard */ - private static boolean convertL4UdpDstMatch(MatchV10Builder matchBuilder, - UdpMatch udpMatch) { + private static boolean convertL4UdpDstMatch(final MatchV10Builder matchBuilder, + final UdpMatch udpMatch) { if (udpMatch.getUdpDestinationPort() != null) { matchBuilder.setTpDst(udpMatch.getUdpDestinationPort().getValue()); return false; @@ -140,8 +141,8 @@ public class MatchConvertorV10Impl implements MatchConvertor { * @param udpMatch * @return is wildCard */ - private static boolean convertL4UdpSrcMatch(MatchV10Builder matchBuilder, - UdpMatch udpMatch) { + private static boolean convertL4UdpSrcMatch(final MatchV10Builder matchBuilder, + final UdpMatch udpMatch) { if (udpMatch.getUdpSourcePort() != null) { matchBuilder.setTpSrc(udpMatch.getUdpSourcePort().getValue()); return false; @@ -154,8 +155,8 @@ public class MatchConvertorV10Impl implements MatchConvertor { * @param tcpMatch * @return is wildCard */ - private static boolean convertL4TpDstMatch(MatchV10Builder matchBuilder, - TcpMatch tcpMatch) { + private static boolean convertL4TpDstMatch(final MatchV10Builder matchBuilder, + final TcpMatch tcpMatch) { if (tcpMatch.getTcpDestinationPort() != null) { matchBuilder.setTpDst(tcpMatch.getTcpDestinationPort().getValue()); return false; @@ -168,8 +169,8 @@ public class MatchConvertorV10Impl implements MatchConvertor { * @param tcpMatch * @return is wildCard */ - private static boolean convertL4TpSrcMatch(MatchV10Builder matchBuilder, - TcpMatch tcpMatch) { + private static boolean convertL4TpSrcMatch(final MatchV10Builder matchBuilder, + final TcpMatch tcpMatch) { if (tcpMatch.getTcpSourcePort() != null) { matchBuilder.setTpSrc(tcpMatch.getTcpSourcePort().getValue()); return false; @@ -182,8 +183,8 @@ public class MatchConvertorV10Impl implements MatchConvertor { * @param ipMatch * @return is wildCard */ - private static boolean convertNwTos(MatchV10Builder matchBuilder, - IpMatch ipMatch) { + private static boolean convertNwTos(final MatchV10Builder matchBuilder, + final IpMatch ipMatch) { if (ipMatch.getIpDscp() != null) { matchBuilder.setNwTos(ipMatch.getIpDscp().getValue()); return false; @@ -196,7 +197,7 @@ public class MatchConvertorV10Impl implements MatchConvertor { * @param ipMatch * @return is wildCard */ - private static boolean convertNwProto(MatchV10Builder matchBuilder, IpMatch ipMatch) { + private static boolean convertNwProto(final MatchV10Builder matchBuilder, final IpMatch ipMatch) { if (ipMatch.getIpProtocol() != null) { matchBuilder.setNwProto(ipMatch.getIpProtocol()); return false; @@ -209,13 +210,12 @@ public class MatchConvertorV10Impl implements MatchConvertor { * @param ipv4 * @return is wildCard */ - private static boolean convertL3Ipv4DstMatch(MatchV10Builder matchBuilder, - Ipv4Match ipv4) { + private static boolean convertL3Ipv4DstMatch(final MatchV10Builder matchBuilder, + final Ipv4Match ipv4) { if(ipv4.getIpv4Destination()!=null){ - String[] addressParts = ipv4.getIpv4Destination().getValue().split("/"); + Iterator addressParts = MatchConvertorImpl.PREFIX_SPLITTER.split(ipv4.getIpv4Destination().getValue()).iterator(); + Ipv4Address ipv4Address = new Ipv4Address(addressParts.next()); Integer prefix = buildPrefix(addressParts); - - Ipv4Address ipv4Address = new Ipv4Address(addressParts[0]); matchBuilder.setNwDst(ipv4Address); matchBuilder.setNwDstMask(prefix.shortValue()); return false; @@ -228,13 +228,13 @@ public class MatchConvertorV10Impl implements MatchConvertor { * @param ipv4 * @return is wildCard */ - private static boolean convertL3Ipv4SrcMatch(MatchV10Builder matchBuilder, - Ipv4Match ipv4) { + private static boolean convertL3Ipv4SrcMatch(final MatchV10Builder matchBuilder, + final Ipv4Match ipv4) { if(ipv4.getIpv4Source()!=null){ - String[] addressParts = ipv4.getIpv4Source().getValue().split(MatchConvertorImpl.PREFIX_SEPARATOR); - Ipv4Address ipv4Address = new Ipv4Address(addressParts[0]); + Iterator addressParts = MatchConvertorImpl.PREFIX_SPLITTER.split(ipv4.getIpv4Source().getValue()).iterator(); + Ipv4Address ipv4Address = new Ipv4Address(addressParts.next()); int prefix = buildPrefix(addressParts); - + matchBuilder.setNwSrc(ipv4Address); matchBuilder.setNwSrcMask((short) prefix); return false; @@ -246,10 +246,10 @@ public class MatchConvertorV10Impl implements MatchConvertor { * @param addressParts * @return */ - private static int buildPrefix(String[] addressParts) { + private static int buildPrefix(final Iterator addressParts) { int prefix = 32; - if (addressParts.length > 1) { - prefix = Integer.parseInt(addressParts[1]); + if (addressParts.hasNext()) { + prefix = Integer.parseInt(addressParts.next()); } return prefix; } @@ -257,10 +257,10 @@ public class MatchConvertorV10Impl implements MatchConvertor { /** * @param matchBuilder * @param vlanMatch - * @return + * @return */ - private static boolean convertDlVlanPcp(MatchV10Builder matchBuilder, - VlanMatch vlanMatch) { + private static boolean convertDlVlanPcp(final MatchV10Builder matchBuilder, + final VlanMatch vlanMatch) { if (vlanMatch.getVlanPcp() != null) { matchBuilder.setDlVlanPcp(vlanMatch.getVlanPcp().getValue()); return false; @@ -271,9 +271,9 @@ public class MatchConvertorV10Impl implements MatchConvertor { /** * @param matchBuilder * @param vlanMatch - * @return + * @return */ - private static boolean convertDlVlan(MatchV10Builder matchBuilder, VlanMatch vlanMatch) { + private static boolean convertDlVlan(final MatchV10Builder matchBuilder, final VlanMatch vlanMatch) { if (vlanMatch.getVlanId() != null) { matchBuilder.setDlVlan(vlanMatch.getVlanId().getVlanId().getValue()); return false; @@ -286,8 +286,8 @@ public class MatchConvertorV10Impl implements MatchConvertor { * @param ethernetMatch * @return is wildCard */ - private static boolean convertEthernetDlType(MatchV10Builder matchBuilder, - EthernetMatch ethernetMatch) { + private static boolean convertEthernetDlType(final MatchV10Builder matchBuilder, + final EthernetMatch ethernetMatch) { if (ethernetMatch.getEthernetType() != null) { matchBuilder.setDlType(ethernetMatch.getEthernetType().getType().getValue().intValue()); return false; @@ -300,8 +300,8 @@ public class MatchConvertorV10Impl implements MatchConvertor { * @param ethernetMatch * @return is wildCard */ - private static boolean convertEthernetDlSrc(MatchV10Builder matchBuilder, - EthernetMatch ethernetMatch) { + private static boolean convertEthernetDlSrc(final MatchV10Builder matchBuilder, + final EthernetMatch ethernetMatch) { if (ethernetMatch.getEthernetSource() != null) { matchBuilder.setDlSrc(ethernetMatch.getEthernetSource().getAddress()); return false; @@ -314,8 +314,8 @@ public class MatchConvertorV10Impl implements MatchConvertor { * @param ethernetMatch * @return is wildCard */ - private static boolean convertEthernetDlDst(MatchV10Builder matchBuilder, - EthernetMatch ethernetMatch) { + private static boolean convertEthernetDlDst(final MatchV10Builder matchBuilder, + final EthernetMatch ethernetMatch) { if (ethernetMatch.getEthernetDestination() != null) { matchBuilder.setDlDst(ethernetMatch.getEthernetDestination().getAddress()); return false; @@ -327,7 +327,7 @@ public class MatchConvertorV10Impl implements MatchConvertor { * @param matchBuilder * @param inPort */ - private static boolean convertInPortMatch(MatchV10Builder matchBuilder, NodeConnectorId inPort) { + private static boolean convertInPortMatch(final MatchV10Builder matchBuilder, final NodeConnectorId inPort) { if (inPort != null) { matchBuilder.setInPort(InventoryDataServiceUtil.portNumberfromNodeConnectorId(inPort).intValue()); return false;