Introduce an easy way to check whether an IP address is multicast or not

Change-Id: I192a1b3e04b843fa0446d011cc98393a1950a5a9
diff --git a/apps/igmp/src/main/java/org/onosproject/igmp/IgmpSnoop.java b/apps/igmp/src/main/java/org/onosproject/igmp/IgmpSnoop.java
index 4a3fc94..b9aeafb 100644
--- a/apps/igmp/src/main/java/org/onosproject/igmp/IgmpSnoop.java
+++ b/apps/igmp/src/main/java/org/onosproject/igmp/IgmpSnoop.java
@@ -419,11 +419,11 @@
 
 
             if (ip.getProtocol() != IPv4.PROTOCOL_IGMP ||
-                    !IpPrefix.MULTICAST_RANGE.contains(gaddr)) {
+                    !IpPrefix.IPV4_MULTICAST_RANGE.contains(gaddr)) {
                 return;
             }
 
-            if (IpPrefix.MULTICAST_RANGE.contains(saddr)) {
+            if (IpPrefix.IPV4_MULTICAST_RANGE.contains(saddr)) {
                 log.debug("IGMP Picked up a packet with a multicast source address.");
                 return;
             }
diff --git a/utils/misc/src/main/java/org/onlab/packet/IpAddress.java b/utils/misc/src/main/java/org/onlab/packet/IpAddress.java
index 5fdd327..9545fa4 100644
--- a/utils/misc/src/main/java/org/onlab/packet/IpAddress.java
+++ b/utils/misc/src/main/java/org/onlab/packet/IpAddress.java
@@ -314,6 +314,17 @@
         return isIp4() && octets[0] == (byte) 169;
     }
 
+    /**
+     * Check if this IP address is a multicast address.
+     *
+     * @return true if this address a multicast address
+     */
+    public boolean isMulticast() {
+        return isIp4() ?
+                Ip4Prefix.IPV4_MULTICAST_RANGE.contains(this.getIp4Address()) :
+                Ip6Prefix.IPV6_MULTICAST_RANGE.contains(this.getIp6Address());
+    }
+
     @Override
     public int compareTo(IpAddress o) {
         // Compare first the version
diff --git a/utils/misc/src/main/java/org/onlab/packet/IpPrefix.java b/utils/misc/src/main/java/org/onlab/packet/IpPrefix.java
index 81a4971..7812045 100644
--- a/utils/misc/src/main/java/org/onlab/packet/IpPrefix.java
+++ b/utils/misc/src/main/java/org/onlab/packet/IpPrefix.java
@@ -27,11 +27,27 @@
  * </p>
  */
 public class IpPrefix {
-    // Maximum network mask length
+    /**
+     * Longest IPv4 network prefix.
+     */
     public static final int MAX_INET_MASK_LENGTH = IpAddress.INET_BIT_LENGTH;
+    /**
+     * Longest IPv6 network prefix.
+     */
     public static final int MAX_INET6_MASK_LENGTH = IpAddress.INET6_BIT_LENGTH;
-
+    /**
+     * An IpPrefix that contains all IPv4 multicast addresses.
+     */
+    @Deprecated
     public static final IpPrefix MULTICAST_RANGE = IpPrefix.valueOf("224.0.0.0/4");
+    /**
+     * An IpPrefix that contains all IPv4 multicast addresses.
+     */
+    public static final IpPrefix IPV4_MULTICAST_RANGE = IpPrefix.valueOf("224.0.0.0/4");
+    /**
+     * An IpPrefix that contains all IPv6 multicast addresses.
+     */
+    public static final IpPrefix IPV6_MULTICAST_RANGE = IpPrefix.valueOf("ff00::/8");
 
     private final IpAddress address;
     private final short prefixLength;
diff --git a/utils/misc/src/test/java/org/onlab/packet/IpAddressTest.java b/utils/misc/src/test/java/org/onlab/packet/IpAddressTest.java
index 8618c46..8505d10 100644
--- a/utils/misc/src/test/java/org/onlab/packet/IpAddressTest.java
+++ b/utils/misc/src/test/java/org/onlab/packet/IpAddressTest.java
@@ -769,6 +769,21 @@
     }
 
     /**
+     * Tests if the address is a multicast address.
+     */
+    @Test
+    public void testIsMulticast() {
+        IpAddress v4Unicast = IpAddress.valueOf("10.0.0.1");
+        IpAddress v4Multicast = IpAddress.valueOf("224.0.0.1");
+        IpAddress v6Unicast = IpAddress.valueOf("1000::1");
+        IpAddress v6Multicast = IpAddress.valueOf("ff02::1");
+        assertFalse(v4Unicast.isMulticast());
+        assertTrue(v4Multicast.isMulticast());
+        assertFalse(v6Unicast.isMulticast());
+        assertTrue(v6Multicast.isMulticast());
+    }
+
+    /**
      * Tests comparison of {@link IpAddress} for IPv4.
      */
     @Test