Committed by
Gerrit Code Review
Modified host discovery to suppress discovery of self-assigned IP addresses.
Change-Id: I40e7c20a6f5b76abe9d9481a135581431e8fcd9f
Showing
3 changed files
with
22 additions
and
2 deletions
... | @@ -289,7 +289,7 @@ public class HostLocationProvider extends AbstractProvider implements HostProvid | ... | @@ -289,7 +289,7 @@ public class HostLocationProvider extends AbstractProvider implements HostProvid |
289 | private void updateLocationIP(HostId hid, MacAddress mac, | 289 | private void updateLocationIP(HostId hid, MacAddress mac, |
290 | VlanId vlan, HostLocation hloc, | 290 | VlanId vlan, HostLocation hloc, |
291 | IpAddress ip) { | 291 | IpAddress ip) { |
292 | - HostDescription desc = ip.isZero() ? | 292 | + HostDescription desc = ip.isZero() || ip.isSelfAssigned() ? |
293 | new DefaultHostDescription(mac, vlan, hloc) : | 293 | new DefaultHostDescription(mac, vlan, hloc) : |
294 | new DefaultHostDescription(mac, vlan, hloc, ip); | 294 | new DefaultHostDescription(mac, vlan, hloc, ip); |
295 | try { | 295 | try { | ... | ... |
... | @@ -294,7 +294,7 @@ public class IpAddress implements Comparable<IpAddress> { | ... | @@ -294,7 +294,7 @@ public class IpAddress implements Comparable<IpAddress> { |
294 | /** | 294 | /** |
295 | * Check if this IP address is zero. | 295 | * Check if this IP address is zero. |
296 | * | 296 | * |
297 | - * @return true if this address is zero. | 297 | + * @return true if this address is zero |
298 | */ | 298 | */ |
299 | public boolean isZero() { | 299 | public boolean isZero() { |
300 | for (byte b : octets) { | 300 | for (byte b : octets) { |
... | @@ -305,6 +305,15 @@ public class IpAddress implements Comparable<IpAddress> { | ... | @@ -305,6 +305,15 @@ public class IpAddress implements Comparable<IpAddress> { |
305 | return true; | 305 | return true; |
306 | } | 306 | } |
307 | 307 | ||
308 | + /** | ||
309 | + * Check if this IP address is self-assigned. | ||
310 | + * | ||
311 | + * @return true if this address is self-assigned | ||
312 | + */ | ||
313 | + public boolean isSelfAssigned() { | ||
314 | + return isIp4() && octets[0] == (byte) 169; | ||
315 | + } | ||
316 | + | ||
308 | @Override | 317 | @Override |
309 | public int compareTo(IpAddress o) { | 318 | public int compareTo(IpAddress o) { |
310 | // Compare first the version | 319 | // Compare first the version | ... | ... |
... | @@ -758,6 +758,17 @@ public class IpAddressTest { | ... | @@ -758,6 +758,17 @@ public class IpAddressTest { |
758 | } | 758 | } |
759 | 759 | ||
760 | /** | 760 | /** |
761 | + * Tests if address is self-assigned for IPv4. | ||
762 | + */ | ||
763 | + @Test | ||
764 | + public void testIsSelfAssignedIpv4() { | ||
765 | + IpAddress normalIP = IpAddress.valueOf("10.0.0.1"); | ||
766 | + IpAddress selfAssignedIP = IpAddress.valueOf("169.1.2.3"); | ||
767 | + assertFalse(normalIP.isSelfAssigned()); | ||
768 | + assertTrue(selfAssignedIP.isSelfAssigned()); | ||
769 | + } | ||
770 | + | ||
771 | + /** | ||
761 | * Tests comparison of {@link IpAddress} for IPv4. | 772 | * Tests comparison of {@link IpAddress} for IPv4. |
762 | */ | 773 | */ |
763 | @Test | 774 | @Test | ... | ... |
-
Please register or login to post a comment