Extend host structures to store multiple locations
Also update host location format in CLI and REST API
Change-Id: I0fbd655f642627dd3eb8a2925f83a3ee016fe4aa
diff --git a/core/store/dist/src/main/java/org/onosproject/store/host/impl/DistributedHostStore.java b/core/store/dist/src/main/java/org/onosproject/store/host/impl/DistributedHostStore.java
index c65ca4b..64d24a7 100644
--- a/core/store/dist/src/main/java/org/onosproject/store/host/impl/DistributedHostStore.java
+++ b/core/store/dist/src/main/java/org/onosproject/store/host/impl/DistributedHostStore.java
@@ -160,7 +160,7 @@
if (!Objects.equals(existingHost.providerId(), providerId) ||
!Objects.equals(existingHost.mac(), hostDescription.hwAddress()) ||
!Objects.equals(existingHost.vlan(), hostDescription.vlan()) ||
- !Objects.equals(existingHost.location(), hostDescription.location())) {
+ !Objects.equals(existingHost.locations(), hostDescription.locations())) {
return true;
}
@@ -194,7 +194,6 @@
existingHost -> shouldUpdate(existingHost, providerId,
hostDescription, replaceIPs),
(id, existingHost) -> {
- HostLocation location = hostDescription.location();
final Set<IpAddress> addresses;
if (existingHost == null || replaceIPs) {
@@ -219,7 +218,7 @@
hostId,
hostDescription.hwAddress(),
hostDescription.vlan(),
- location,
+ hostDescription.locations(),
addresses,
configured,
annotations);
@@ -253,8 +252,9 @@
hostId,
existingHost.mac(),
existingHost.vlan(),
- existingHost.location(),
+ existingHost.locations(),
ImmutableSet.copyOf(addresses),
+ existingHost.configured(),
existingHost.annotations());
} else {
return existingHost;
@@ -299,7 +299,7 @@
@Override
public Set<Host> getConnectedHosts(ConnectPoint connectPoint) {
Set<Host> filtered = hosts.entrySet().stream()
- .filter(entry -> entry.getValue().location().equals(connectPoint))
+ .filter(entry -> entry.getValue().locations().contains(connectPoint))
.map(Map.Entry::getValue)
.collect(Collectors.toSet());
return ImmutableSet.copyOf(filtered);
@@ -308,7 +308,8 @@
@Override
public Set<Host> getConnectedHosts(DeviceId deviceId) {
Set<Host> filtered = hosts.entrySet().stream()
- .filter(entry -> entry.getValue().location().deviceId().equals(deviceId))
+ .filter(entry -> entry.getValue().locations().stream()
+ .map(HostLocation::deviceId).anyMatch(dpid -> dpid.equals(deviceId)))
.map(Map.Entry::getValue)
.collect(Collectors.toSet());
return ImmutableSet.copyOf(filtered);
@@ -382,7 +383,7 @@
case UPDATE:
updateHostsByIp(host);
DefaultHost prevHost = checkNotNull(event.oldValue().value());
- if (!Objects.equals(prevHost.location(), host.location())) {
+ if (!Objects.equals(prevHost.locations(), host.locations())) {
notifyDelegate(new HostEvent(HOST_MOVED, host, prevHost));
} else if (!Objects.equals(prevHost, host)) {
notifyDelegate(new HostEvent(HOST_UPDATED, host, prevHost));