From: Alessandro Boch Date: Sat, 31 Aug 2013 00:31:28 +0000 (-0700) Subject: Fix IP/MASK intersection in Match X-Git-Tag: releasepom-0.1.0~140 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=commitdiff_plain;h=f4f0a778c5e55053750590b0686d6e2b838031e6;hp=6806719ffe0a4ac6d0585faeadc86fc947e8095b Fix IP/MASK intersection in Match - Match.getIntersection() picks the wrong IP/MASK - Updated Junit to assert on expected behavior Change-Id: Iae49984ece6be28855f5835803cb3d6b7c94fa50 Signed-off-by: Alessandro Boch --- diff --git a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/match/Match.java b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/match/Match.java index 30c25af57f..b6381cc7d8 100644 --- a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/match/Match.java +++ b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/match/Match.java @@ -354,7 +354,7 @@ public class Match implements Cloneable, Serializable { .getSubnetMaskLength(thisMask); int otherMaskLen = (otherMask == null) ? ((otherAddress instanceof Inet4Address) ? 32 : 128) : NetUtils .getSubnetMaskLength(otherMask); - if (otherMaskLen < thisMaskLen) { + if (thisMaskLen < otherMaskLen) { intersection.setField(new MatchField(type, NetUtils.getSubnetPrefix(otherAddress, otherMaskLen), otherMask)); } else { diff --git a/opendaylight/sal/api/src/test/java/org/opendaylight/controller/sal/match/MatchTest.java b/opendaylight/sal/api/src/test/java/org/opendaylight/controller/sal/match/MatchTest.java index f3c7a95b0e..e3333cf78c 100644 --- a/opendaylight/sal/api/src/test/java/org/opendaylight/controller/sal/match/MatchTest.java +++ b/opendaylight/sal/api/src/test/java/org/opendaylight/controller/sal/match/MatchTest.java @@ -532,6 +532,8 @@ public class MatchTest { InetAddress ipm2 = InetAddress.getByName("255.255.255.0"); InetAddress ip3 = InetAddress.getByName("1.3.0.0"); InetAddress ipm3 = InetAddress.getByName("255.255.0.0"); + InetAddress ip4 = InetAddress.getByName("1.3.4.4"); + InetAddress ipm4 = InetAddress.getByName("255.255.255.0"); Match m1 = new Match(); m1.setField(MatchType.DL_TYPE, ethType); @@ -562,8 +564,9 @@ public class MatchTest { Match i = m1.getIntersection(m2); Assert.assertTrue(((Short)i.getField(MatchType.DL_TYPE).getValue()).equals(ethType)); - Assert.assertTrue(((InetAddress)i.getField(MatchType.NW_SRC).getValue()).equals(ip2)); - Assert.assertTrue(((InetAddress)i.getField(MatchType.NW_SRC).getMask()).equals(ipm2)); + // Verify intersection of IP addresses is correct + Assert.assertTrue(((InetAddress)i.getField(MatchType.NW_SRC).getValue()).equals(ip1)); + Assert.assertNull(i.getField(MatchType.NW_SRC).getMask()); // Empty set i = m2.getIntersection(m3); @@ -572,8 +575,14 @@ public class MatchTest { Match m4 = new Match(); m4.setField(MatchType.DL_TYPE, ethType); m4.setField(MatchType.NW_PROTO, IPProtocols.TCP.byteValue()); + m3.setField(MatchType.NW_SRC, ip4, ipm4); Assert.assertTrue(m4.intersetcs(m3)); + // Verify intersection of IP and IP mask addresses is correct + Match ii = m3.getIntersection(m4); + Assert.assertTrue(((InetAddress)ii.getField(MatchType.NW_SRC).getValue()).equals(ip4)); + Assert.assertTrue(((InetAddress)ii.getField(MatchType.NW_SRC).getMask()).equals(ipm4)); + Match m5 = new Match(); m5.setField(MatchType.DL_TYPE, ethType); m3.setField(MatchType.NW_SRC, ip3, ipm3);