import com.google.common.annotations.VisibleForTesting;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Prefix;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Prefix;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;
import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.MacAddressFilter;
import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatch;
import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Layer3Match;
import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4Match;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv6Match;
/**
* @author joe
verdict = MatchComparatorHelper.compareIpv4PrefixNullSafe(statsIpv4Match.getIpv4Source(),
storedIpv4Match.getIpv4Source());
}
- } else {
+ } else if(statsLayer3Match instanceof Ipv6Match && storedLayer3Match instanceof Ipv6Match) {
+ final Ipv6Match statsIpv6Match = (Ipv6Match) statsLayer3Match;
+ final Ipv6Match storedIpv6Match = (Ipv6Match) storedLayer3Match;
+ verdict = MatchComparatorHelper.compareIpv6PrefixNullSafe(storedIpv6Match.getIpv6Destination(),
+ statsIpv6Match.getIpv6Destination());
+ if (verdict) {
+ verdict = MatchComparatorHelper.compareIpv6PrefixNullSafe(statsIpv6Match.getIpv6Source(),
+ storedIpv6Match.getIpv6Source());
+ }
+ }else {
final Boolean nullCheckOut = checkNullValues(storedLayer3Match, statsLayer3Match);
if (nullCheckOut != null) {
verdict = nullCheckOut;
return verdict;
}
+
/**
* TODO: why don't we use the default Ipv4Prefix.equals()?
*
return (statsIpAddressInt.getIp() == storedIpAddressInt.getIp());
}
+
+ private static boolean IpAddressEquals(Ipv6Prefix statsIpv6, Ipv6Prefix storedIpv6) {
+ final String[] statsIpMask = statsIpv6.getValue().split("/");
+ final String[] storedIpMask = storedIpv6.getValue().split("/");
+ if(! (statsIpMask.length > 1 && storedIpMask.length > 1 && statsIpMask[1].equals(storedIpMask[1]))){
+ return false;
+ }
+ if(InetAddresses.forString(statsIpMask[0]).equals(InetAddresses.forString(storedIpMask[0]))){
+ return true;
+ }
+ return false;
+ }
+
+
static Boolean checkNullValues(final Object v1, final Object v2) {
Boolean verdict = null;
if (v1 == null && v2 != null) {
return verdict;
}
+ private static boolean compareIpv6PrefixNullSafe(Ipv6Prefix statsIpv6, Ipv6Prefix storedIpv6) {
+ boolean verdict = true;
+ final Boolean checkDestNullValuesOut = checkNullValues(statsIpv6, storedIpv6);
+ if (checkDestNullValuesOut != null) {
+ verdict = checkDestNullValuesOut;
+ } else if (!IpAddressEquals(statsIpv6, storedIpv6)) {
+ verdict = false;
+ }
+
+ return verdict;
+ }
+
/**
* Method return integer version of ip address. Converted int will be mask if mask specified
*/
package org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.match;
import static org.opendaylight.openflowjava.util.ByteBufUtils.macAddressToString;
-
import com.google.common.base.Optional;
import java.math.BigInteger;
import java.nio.ByteBuffer;
private static final short PROTO_ICMPV4 = 1;
private static final String NO_IP = "0.0.0.0/0";
+ // Pre-calculated masks for the 33 possible values. Do not give them out, but clone() them as they may
+ // end up being leaked and vulnerable.
+ private static final byte[][] IPV4_MASKS;
+ static {
+ final byte[][] tmp = new byte[33][];
+ for (int i = 0; i <= 32; ++i) {
+ final int mask = 0xffffffff << (32 - i);
+ tmp[i] = new byte[]{(byte) (mask >>> 24), (byte) (mask >>> 16), (byte) (mask >>> 8), (byte) mask};
+ }
+
+ IPV4_MASKS = tmp;
+ }
+
@Override
public List<MatchEntry> convert(
final org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match match, final BigInteger datapathid) {
}
- private void protocolMatchFields(List<MatchEntry> matchEntryList,
- ProtocolMatchFields protocolMatchFields) {
+ private static void protocolMatchFields(final List<MatchEntry> matchEntryList,
+ final ProtocolMatchFields protocolMatchFields) {
if (protocolMatchFields != null) {
if (protocolMatchFields.getMplsLabel() != null) {
matchEntryList.add(toOfMplsLabel(protocolMatchFields.getMplsLabel()));
}
- private void layer3Match(List<MatchEntry> matchEntryList,
- Layer3Match layer3Match) {
+ private static void layer3Match(final List<MatchEntry> matchEntryList, final Layer3Match layer3Match) {
if (layer3Match != null) {
if (layer3Match instanceof Ipv4Match) {
Ipv4Match ipv4Match = (Ipv4Match) layer3Match;
}
- private void icmpv6Match(List<MatchEntry> matchEntryList,
- Icmpv6Match icmpv6Match) {
+ private static void icmpv6Match(final List<MatchEntry> matchEntryList, final Icmpv6Match icmpv6Match) {
if (icmpv6Match != null) {
if (icmpv6Match.getIcmpv6Type() != null) {
matchEntryList.add(toOfIcmpv6Type(icmpv6Match.getIcmpv6Type()));
}
- private void icmpv4Match(List<MatchEntry> matchEntryList,
- Icmpv4Match icmpv4Match) {
+ private static void icmpv4Match(final List<MatchEntry> matchEntryList, final Icmpv4Match icmpv4Match) {
if (icmpv4Match != null) {
if (icmpv4Match.getIcmpv4Type() != null) {
matchEntryList.add(toOfIcmpv4Type(icmpv4Match.getIcmpv4Type()));
}
- private void layer4Match(List<MatchEntry> matchEntryList,
- Layer4Match layer4Match) {
+ private static void layer4Match(final List<MatchEntry> matchEntryList, final Layer4Match layer4Match) {
if (layer4Match != null) {
if (layer4Match instanceof TcpMatch) {
TcpMatch tcpMatch = (TcpMatch) layer4Match;
}
- private void ipMatch(List<MatchEntry> matchEntryList, IpMatch ipMatch) {
+ private static void ipMatch(final List<MatchEntry> matchEntryList, final IpMatch ipMatch) {
if (ipMatch != null) {
if (ipMatch.getIpDscp() != null) {
matchEntryList.add(toOfIpDscp(ipMatch.getIpDscp()));
if (ipMatch.getIpProtocol() != null) {
matchEntryList.add(toOfIpProto(ipMatch.getIpProtocol()));
}
-
}
}
- private void vlanMatch(List<MatchEntry> matchEntryList,
- VlanMatch vlanMatch) {
+ private static void vlanMatch(final List<MatchEntry> matchEntryList, final VlanMatch vlanMatch) {
if (vlanMatch != null) {
if (vlanMatch.getVlanId() != null) {
VlanId vlanId = vlanMatch.getVlanId();
}
- private void ethernetMatch(List<MatchEntry> matchEntryList,
- EthernetMatch ethernetMatch) {
+ private static void ethernetMatch(final List<MatchEntry> matchEntryList, final EthernetMatch ethernetMatch) {
if (ethernetMatch != null) {
EthernetDestination ethernetDestination = ethernetMatch.getEthernetDestination();
if (ethernetDestination != null) {
}
if (prefix != 0) {
- int mask = 0xffffffff << (32 - prefix);
- byte[] maskBytes = new byte[]{(byte) (mask >>> 24), (byte) (mask >>> 16), (byte) (mask >>> 8),
- (byte) mask};
- return maskBytes;
+ // clone() is necessary to protect our constants
+ return IPV4_MASKS[prefix].clone();
}
return null;
}