Allow host provider to remove a learnt host provided by others
Before, a host provider is allowed to remove
O learnt hosts provided by itself
O configured hosts provided by itself
X learnt hosts provided by other
X configured hosts provided by other
After, a host provider is allowed to remove
O learnt hosts provided by itself
O configured hosts provided by itself
O learnt hosts provided by other
X configured hosts provided by other
Also, fix tests in HostManagerTest
Change-Id: Ibce4567017a74cdec1dd77bd82de5b9de2559b5f
diff --git a/core/net/src/main/java/org/onosproject/net/host/impl/HostManager.java b/core/net/src/main/java/org/onosproject/net/host/impl/HostManager.java
index 66159f7..b7a38e6 100644
--- a/core/net/src/main/java/org/onosproject/net/host/impl/HostManager.java
+++ b/core/net/src/main/java/org/onosproject/net/host/impl/HostManager.java
@@ -464,10 +464,13 @@
store.removePendingHostLocation(probeMac);
}
+ /**
+ * Providers should only be able to remove a host that is provided by itself,
+ * or a host that is not configured.
+ */
private boolean allowedToChange(HostId hostId) {
- // Disallow removing inexistent host or host provided by others
Host host = store.getHost(hostId);
- return host != null && host.providerId().equals(provider().id());
+ return host == null || !host.configured() || host.providerId().equals(provider().id());
}
}
diff --git a/core/net/src/test/java/org/onosproject/net/host/impl/HostManagerTest.java b/core/net/src/test/java/org/onosproject/net/host/impl/HostManagerTest.java
index ba27dcb..f2beda1 100644
--- a/core/net/src/test/java/org/onosproject/net/host/impl/HostManagerTest.java
+++ b/core/net/src/test/java/org/onosproject/net/host/impl/HostManagerTest.java
@@ -259,7 +259,8 @@
}
/**
- * Providers should only be able to remove a host provided by itself.
+ * Providers should only be able to remove a host that is provided by itself,
+ * or a host that is not configured.
*/
@Test
public void hostVanishedWithMultipleProviders() {
@@ -267,16 +268,15 @@
configured(HID2, MAC2, VLAN2, LOC2, IP2);
providerService2.hostVanished(HID1);
- assertNotNull("host should not be removed", mgr.getHost(HID1));
+ assertNull("Should be able to remove learnt host", mgr.getHost(HID1));
providerService.hostVanished(HID2);
- assertNotNull("host should not be removed", mgr.getHost(HID2));
-
- providerService.hostVanished(HID1);
- assertNull("host should be removed", mgr.getHost(HID1));
+ assertNotNull("Should not be able to remove configured host since the provider is different",
+ mgr.getHost(HID2));
providerService2.hostVanished(HID2);
- assertNull("host should be removed", mgr.getHost(HID2));
+ assertNull("Should be able to remove configured host when provider is the same",
+ mgr.getHost(HID2));
}
private void validateHosts(