Thomas Vachuska
Committed by Gerrit Code Review

Modified host discovery to suppress discovery of self-assigned IP addresses.

Change-Id: I40e7c20a6f5b76abe9d9481a135581431e8fcd9f
......@@ -289,7 +289,7 @@ public class HostLocationProvider extends AbstractProvider implements HostProvid
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 {
......
......@@ -294,7 +294,7 @@ public class IpAddress implements Comparable<IpAddress> {
/**
* 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 @@ public class IpAddress implements Comparable<IpAddress> {
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
......
......@@ -758,6 +758,17 @@ public class IpAddressTest {
}
/**
* 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
......