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());
}
}