Yuta HIGUCHI
Committed by Gerrit Code Review

Handle null secondary path properly

Change-Id: Ie537c9fc7b6751ca071b3c7bf1e465bafe7913d3
......@@ -20,7 +20,6 @@ import org.onosproject.net.provider.ProviderId;
import java.util.List;
import java.util.Objects;
import static com.google.common.collect.ImmutableSet.of;
/**
* Default implementation of a network disjoint path pair.
......@@ -40,7 +39,8 @@ public class DefaultDisjointPath extends DefaultPath implements DisjointPath {
* @param path2 backup path
*/
public DefaultDisjointPath(ProviderId providerId, DefaultPath path1, DefaultPath path2) {
super(providerId, path1.links(), path1.cost() + path2.cost());
// Note: cost passed to super will never be used
super(providerId, path1.links(), path1.cost());
this.path1 = path1;
this.path2 = path2;
}
......@@ -74,7 +74,9 @@ public class DefaultDisjointPath extends DefaultPath implements DisjointPath {
@Override
public int hashCode() {
return Objects.hash(of(path1, path2), src(), dst());
// Note: DisjointPath with primary and secondary swapped
// must result in same hashCode
return Objects.hash(Objects.hashCode(path1) + Objects.hashCode(path2), src(), dst());
}
@Override
......@@ -84,7 +86,8 @@ public class DefaultDisjointPath extends DefaultPath implements DisjointPath {
}
if (obj instanceof DefaultDisjointPath) {
final DefaultDisjointPath other = (DefaultDisjointPath) obj;
return Objects.equals(this.path1, other.path1) && Objects.equals(this.path2, other.path2);
return (Objects.equals(this.path1, other.path1) && Objects.equals(this.path2, other.path2)) ||
(Objects.equals(this.path1, other.path2) && Objects.equals(this.path2, other.path1));
}
return false;
}
......