calclulate IP addresses hash only from masked part of address
[openflowplugin.git] / openflowplugin-impl / src / test / java / org / opendaylight / openflowplugin / impl / util / HashUtilTest.java
index 9598dc0c88721edf7eed86e0a516fabca0c1bea9..03637cab17f8610cf8ea89711afdc74e326cf5d0 100644 (file)
@@ -47,6 +47,12 @@ public class HashUtilTest {
 
     private static final Ipv6Prefix shortIpv6 = new Ipv6Prefix("fe80::2acf:e9ff:fe21:6431/128");
     private static final Ipv6Prefix fullIpv6 = new Ipv6Prefix("fe80:0000:2acf:e9ff:fe21:6431:0000:0000/128");
+    private static final Ipv6Prefix[] IPV_6_PREFIXES_WITH_MASK = {
+            new Ipv6Prefix("FFFF:0DB8:0000:0000:0000:0000:1428:57ab/72"),
+            new Ipv6Prefix("2001:0DB8:0000:0000:0000:0000:1428:57ab/94"),
+            new Ipv6Prefix("0DB8:2001:0000:0000:0000:0000:1428:57ab/32"),
+            new Ipv6Prefix("2001:0DB8:0000:0000:0000:0000:57ab:1428/64")
+    };
 
     @Test
     public void testCalculateMatchHash() throws Exception {
@@ -87,4 +93,15 @@ public class HashUtilTest {
             Assert.assertNotEquals(hash_n, hash_n1);
         }
     }
+    @Test
+    public void testCalculateIpv6PrefixHashWithMask() {
+        for (int i = 0; i < IPV_6_PREFIXES.length - 1; i++) {
+            int hash_n = HashUtil.calculateIpv6PrefixHash(IPV_6_PREFIXES_WITH_MASK[i]);
+            int hash_n1 = HashUtil.calculateIpv6PrefixHash(IPV_6_PREFIXES_WITH_MASK[i + 1]);
+            Assert.assertNotNull(hash_n);
+            Assert.assertNotNull(hash_n1);
+            Assert.assertNotEquals(hash_n, hash_n1);
+        }
+    }
+
 }
\ No newline at end of file