blob: 1a0507b9b1d1a453d19760951bbddf59973b52bb [file] [log] [blame]
Saurav Das7bcbe702017-06-13 15:35:54 -07001/*
2 * Copyright 2015-present Open Networking Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package org.onosproject.segmentrouting.grouphandler;
18
19import static com.google.common.base.MoreObjects.toStringHelper;
20
21import java.util.HashSet;
22import java.util.Map;
23import java.util.Objects;
24import java.util.Set;
25
26import org.onosproject.net.DeviceId;
27
28public class NextNeighbors {
29 private final Map<DeviceId, Set<DeviceId>> dstNextHops;
30 private final int nextId;
31
32 public NextNeighbors(Map<DeviceId, Set<DeviceId>> dstNextHops, int nextId) {
33 this.dstNextHops = dstNextHops;
34 this.nextId = nextId;
35 }
36
37 public Map<DeviceId, Set<DeviceId>> dstNextHops() {
38 return dstNextHops;
39 }
40
41 public Set<DeviceId> nextHops(DeviceId deviceId) {
42 return dstNextHops.get(deviceId);
43 }
44
45 public int nextId() {
46 return nextId;
47 }
48
49 public boolean containsNextHop(DeviceId nextHopId) {
50 for (Set<DeviceId> nextHops : dstNextHops.values()) {
51 if (nextHops != null && nextHops.contains(nextHopId)) {
52 return true;
53 }
54 }
55 return false;
56 }
57
58 public Set<DeviceId> getDstForNextHop(DeviceId nextHopId) {
59 Set<DeviceId> dstSet = new HashSet<>();
60 for (DeviceId dstKey : dstNextHops.keySet()) {
61 if (dstNextHops.get(dstKey).contains(nextHopId)) {
62 dstSet.add(dstKey);
63 }
64 }
65 return dstSet;
66 }
67
68 @Override
69 public boolean equals(Object o) {
70 if (this == o) {
71 return true;
72 }
73 if (!(o instanceof NextNeighbors)) {
74 return false;
75 }
76 NextNeighbors that = (NextNeighbors) o;
77 return (this.nextId == that.nextId) &&
78 this.dstNextHops.equals(that.dstNextHops);
79 }
80
81 @Override
82 public int hashCode() {
83 return Objects.hash(nextId, dstNextHops);
84 }
85
86 @Override
87 public String toString() {
88 return toStringHelper(this)
89 .add("nextId", nextId)
90 .add("dstNextHops", dstNextHops)
91 .toString();
92 }
93}