Modified host discovery to suppress discovery of self-assigned IP addresses.
Change-Id: I40e7c20a6f5b76abe9d9481a135581431e8fcd9f
diff --git a/providers/host/src/main/java/org/onosproject/provider/host/impl/HostLocationProvider.java b/providers/host/src/main/java/org/onosproject/provider/host/impl/HostLocationProvider.java
index fa331fa..9a82363 100644
--- a/providers/host/src/main/java/org/onosproject/provider/host/impl/HostLocationProvider.java
+++ b/providers/host/src/main/java/org/onosproject/provider/host/impl/HostLocationProvider.java
@@ -289,7 +289,7 @@
private void updateLocationIP(HostId hid, MacAddress mac,
VlanId vlan, HostLocation hloc,
IpAddress ip) {
- HostDescription desc = ip.isZero() ?
+ HostDescription desc = ip.isZero() || ip.isSelfAssigned() ?
new DefaultHostDescription(mac, vlan, hloc) :
new DefaultHostDescription(mac, vlan, hloc, ip);
try {
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 5b39286..5fdd327 100644
--- a/utils/misc/src/main/java/org/onlab/packet/IpAddress.java
+++ b/utils/misc/src/main/java/org/onlab/packet/IpAddress.java
@@ -294,7 +294,7 @@
/**
* Check if this IP address is zero.
*
- * @return true if this address is zero.
+ * @return true if this address is zero
*/
public boolean isZero() {
for (byte b : octets) {
@@ -305,6 +305,15 @@
return true;
}
+ /**
+ * Check if this IP address is self-assigned.
+ *
+ * @return true if this address is self-assigned
+ */
+ public boolean isSelfAssigned() {
+ return isIp4() && octets[0] == (byte) 169;
+ }
+
@Override
public int compareTo(IpAddress o) {
// Compare first the version
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 003982a..8618c46 100644
--- a/utils/misc/src/test/java/org/onlab/packet/IpAddressTest.java
+++ b/utils/misc/src/test/java/org/onlab/packet/IpAddressTest.java
@@ -758,6 +758,17 @@
}
/**
+ * Tests if address is self-assigned for IPv4.
+ */
+ @Test
+ public void testIsSelfAssignedIpv4() {
+ IpAddress normalIP = IpAddress.valueOf("10.0.0.1");
+ IpAddress selfAssignedIP = IpAddress.valueOf("169.1.2.3");
+ assertFalse(normalIP.isSelfAssigned());
+ assertTrue(selfAssignedIP.isSelfAssigned());
+ }
+
+ /**
* Tests comparison of {@link IpAddress} for IPv4.
*/
@Test