Jonathan Hart
Committed by Gerrit Code Review

Fix establishing local identity with wrong IP address.

ONOS-2406.

Ported from onos-1.2 branch.

Change-Id: I4eda4eeb5ed3218d1063102db4794a535cb9002f
(cherry picked from commit 3dbf89d6)
1 package org.onosproject.store.cluster.impl; 1 package org.onosproject.store.cluster.impl;
2 2
3 -import static java.net.NetworkInterface.getNetworkInterfaces; 3 +import com.google.common.collect.ImmutableSet;
4 -import static java.util.Collections.list; 4 +import com.google.common.collect.Sets;
5 -import static org.onosproject.cluster.DefaultControllerNode.DEFAULT_PORT;
6 -import static org.onosproject.store.consistent.impl.DatabaseManager.PARTITION_DEFINITION_FILE;
7 -import static org.slf4j.LoggerFactory.getLogger;
8 -
9 -import java.io.File;
10 -import java.io.IOException;
11 -import java.net.InetAddress;
12 -import java.net.NetworkInterface;
13 -import java.net.SocketException;
14 -import java.util.Enumeration;
15 -import java.util.Set;
16 -import java.util.stream.Collectors;
17 -
18 import org.apache.felix.scr.annotations.Activate; 5 import org.apache.felix.scr.annotations.Activate;
19 import org.apache.felix.scr.annotations.Component; 6 import org.apache.felix.scr.annotations.Component;
20 import org.apache.felix.scr.annotations.Deactivate; 7 import org.apache.felix.scr.annotations.Deactivate;
...@@ -28,8 +15,20 @@ import org.onosproject.store.consistent.impl.DatabaseDefinition; ...@@ -28,8 +15,20 @@ import org.onosproject.store.consistent.impl.DatabaseDefinition;
28 import org.onosproject.store.consistent.impl.DatabaseDefinitionStore; 15 import org.onosproject.store.consistent.impl.DatabaseDefinitionStore;
29 import org.slf4j.Logger; 16 import org.slf4j.Logger;
30 17
31 -import com.google.common.collect.ImmutableSet; 18 +import java.io.File;
32 -import com.google.common.collect.Sets; 19 +import java.io.IOException;
20 +import java.net.InetAddress;
21 +import java.net.NetworkInterface;
22 +import java.net.SocketException;
23 +import java.util.Enumeration;
24 +import java.util.Set;
25 +import java.util.stream.Collectors;
26 +
27 +import static java.net.NetworkInterface.getNetworkInterfaces;
28 +import static java.util.Collections.list;
29 +import static org.onosproject.cluster.DefaultControllerNode.DEFAULT_PORT;
30 +import static org.onosproject.store.consistent.impl.DatabaseManager.PARTITION_DEFINITION_FILE;
31 +import static org.slf4j.LoggerFactory.getLogger;
33 32
34 /** 33 /**
35 * Implementation of ClusterDefinitionService. 34 * Implementation of ClusterDefinitionService.
...@@ -113,7 +112,10 @@ public class ClusterDefinitionManager implements ClusterDefinitionService { ...@@ -113,7 +112,10 @@ public class ClusterDefinitionManager implements ClusterDefinitionService {
113 Enumeration<InetAddress> inetAddresses = iface.getInetAddresses(); 112 Enumeration<InetAddress> inetAddresses = iface.getInetAddresses();
114 while (inetAddresses.hasMoreElements()) { 113 while (inetAddresses.hasMoreElements()) {
115 IpAddress ip = IpAddress.valueOf(inetAddresses.nextElement()); 114 IpAddress ip = IpAddress.valueOf(inetAddresses.nextElement());
116 - if (matchInterface(ip.toString(), clusterDefinition.getIpPrefix())) { 115 + if (clusterDefinition.getNodes().stream()
116 + .map(NodeInfo::getIp)
117 + .map(IpAddress::valueOf)
118 + .anyMatch(nodeIp -> ip.equals(nodeIp))) {
117 return ip; 119 return ip;
118 } 120 }
119 } 121 }
......