blob: f464e5d38b25bffb6b38536b2d9aeb72f60e4197 [file] [log] [blame]
Jonathan Hart96c146b2017-02-24 16:32:00 -08001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2017-present Open Networking Foundation
Jonathan Hart96c146b2017-02-24 16:32:00 -08003 *
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
Ray Milkey69ec8712017-08-08 13:00:43 -070017package org.onosproject.routeservice;
Jonathan Hart96c146b2017-02-24 16:32:00 -080018
19import com.google.common.collect.ImmutableSet;
20import org.onlab.packet.IpPrefix;
21
22import java.util.Objects;
23import java.util.Set;
24
25import static com.google.common.base.Preconditions.checkNotNull;
26
27/**
28 * A set of routes for a particular prefix in a route table.
29 */
30public class RouteSet {
31 private final RouteTableId tableId;
32
33 private final IpPrefix prefix;
34 private final Set<Route> routes;
35
36 /**
37 * Creates a new route set.
38 *
39 * @param tableId route table ID
40 * @param prefix IP prefix
41 * @param routes routes for the given prefix
42 */
43 public RouteSet(RouteTableId tableId, IpPrefix prefix, Set<Route> 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 */
54 public RouteTableId tableId() {
55 return tableId;
56 }
57
58 /**
59 * Returns the IP prefix.
60 *
61 * @return IP prefix
62 */
63 public IpPrefix prefix() {
64 return prefix;
65 }
66
67 /**
68 * Returns the set of routes.
69 *
70 * @return routes
71 */
72 public Set<Route> 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
87 if (!(other instanceof RouteSet)) {
88 return false;
89 }
90
91 RouteSet that = (RouteSet) 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}