blob: adc8c1c253fd337b8b72bd99fc37199ef77bee59 [file] [log] [blame]
Mohammad Shahidaa7c1232017-08-09 11:13:15 +05301/*
2 * Copyright 2017-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.incubator.net.routing;
18
19import com.google.common.collect.ImmutableSet;
20
21import java.util.Objects;
22import java.util.Set;
23
24import static com.google.common.base.Preconditions.checkNotNull;
25
26/**
27 * A set of routes for a particular prefix in a route table.
28 */
29public class EvpnRouteSet {
Jonathan Harte9c0c6e2017-08-09 16:44:13 -070030 private final EvpnRouteTableId tableId;
Mohammad Shahidaa7c1232017-08-09 11:13:15 +053031
32 private final EvpnPrefix prefix;
33 private final Set<EvpnRoute> routes;
34
35 /**
36 * Creates a new route set.
37 *
38 * @param tableId route table ID
39 * @param prefix IP prefix
40 * @param routes routes for the given prefix
41 */
Jonathan Harte9c0c6e2017-08-09 16:44:13 -070042 public EvpnRouteSet(EvpnRouteTableId tableId, EvpnPrefix prefix, Set<EvpnRoute>
Mohammad Shahidaa7c1232017-08-09 11:13:15 +053043 routes) {
44 this.tableId = checkNotNull(tableId);
45 this.prefix = checkNotNull(prefix);
46 this.routes = ImmutableSet.copyOf(checkNotNull(routes));
47 }
48
49 /**
50 * Returns the route table ID.
51 *
52 * @return route table ID
53 */
Jonathan Harte9c0c6e2017-08-09 16:44:13 -070054 public EvpnRouteTableId tableId() {
Mohammad Shahidaa7c1232017-08-09 11:13:15 +053055 return tableId;
56 }
57
58 /**
59 * Returns the IP prefix.
60 *
61 * @return IP prefix
62 */
63 public EvpnPrefix prefix() {
64 return prefix;
65 }
66
67 /**
68 * Returns the set of routes.
69 *
70 * @return routes
71 */
72 public Set<EvpnRoute> routes() {
73 return routes;
74 }
75
76 @Override
77 public int hashCode() {
78 return Objects.hash(tableId, prefix, routes);
79 }
80
81 @Override
82 public boolean equals(Object other) {
83 if (this == other) {
84 return true;
85 }
86
Jonathan Harte9c0c6e2017-08-09 16:44:13 -070087 if (!(other instanceof EvpnRouteSet)) {
Mohammad Shahidaa7c1232017-08-09 11:13:15 +053088 return false;
89 }
90
91 EvpnRouteSet that = (EvpnRouteSet) other;
92
93 return Objects.equals(this.tableId, that.tableId) &&
94 Objects.equals(this.prefix, that.prefix) &&
95 Objects.equals(this.routes, that.routes);
96 }
97}