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/common/src/test/java/org/onosproject/store/trivial/SimpleHostStore.java b/core/common/src/test/java/org/onosproject/store/trivial/SimpleHostStore.java
index 93fa3f0..e1fea28 100644
--- a/core/common/src/test/java/org/onosproject/store/trivial/SimpleHostStore.java
+++ b/core/common/src/test/java/org/onosproject/store/trivial/SimpleHostStore.java
@@ -106,6 +106,7 @@
descr.vlan(),
descr.location(),
ImmutableSet.copyOf(descr.ipAddress()),
+ descr.configured(),
descr.annotations());
synchronized (this) {
hosts.put(hostId, newhost);
@@ -141,6 +142,7 @@
StoredHost updated = new StoredHost(providerId, host.id(),
host.mac(), host.vlan(),
descr.location(), addresses,
+ descr.configured(),
annotations);
event = new HostEvent(HOST_UPDATED, updated);
synchronized (this) {
@@ -257,8 +259,8 @@
*/
public StoredHost(ProviderId providerId, HostId id,
MacAddress mac, VlanId vlan, HostLocation location,
- Set<IpAddress> ips, Annotations... annotations) {
- super(providerId, id, mac, vlan, location, ips, annotations);
+ Set<IpAddress> ips, boolean configured, Annotations... annotations) {
+ super(providerId, id, mac, vlan, location, ips, configured, annotations);
this.location = location;
}
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(