Added methods to test whether an IP address/prefix is IPv4 or IPv6:
IpAddress.isIp4()
IpAddress.isIp6()
IpPrefix.isIp4()
IpPrefix.isIp6()
Also, added the corresponding unit tests.
Change-Id: I2b1f08501c94d61f75b15f2c6977c0349e313ebd
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 f8d9f2f..699ad47 100644
--- a/utils/misc/src/main/java/org/onlab/packet/IpAddress.java
+++ b/utils/misc/src/main/java/org/onlab/packet/IpAddress.java
@@ -80,6 +80,24 @@
}
/**
+ * Tests whether the IP version of this address is IPv4.
+ *
+ * @return true if the IP version of this address is IPv4, otherwise false.
+ */
+ public boolean isIp4() {
+ return (version() == Ip4Address.VERSION);
+ }
+
+ /**
+ * Tests whether the IP version of this address is IPv6.
+ *
+ * @return true if the IP version of this address is IPv6, otherwise false.
+ */
+ public boolean isIp6() {
+ return (version() == Ip6Address.VERSION);
+ }
+
+ /**
* Gets the {@link Ip4Address} view of the IP address.
*
* @return the {@link Ip4Address} view of the IP address if it is IPv4,