blob: 387dc73dafa7206bbcf010afecc5275baed2c69c [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
Charles Chan50f3f132018-06-21 17:41:50 -070019import com.google.common.base.MoreObjects;
Jonathan Hart96c146b2017-02-24 16:32:00 -080020import com.google.common.collect.ImmutableSet;
21import org.onlab.packet.IpPrefix;
22
23import java.util.Objects;
24import java.util.Set;
25
26import static com.google.common.base.Preconditions.checkNotNull;
27
28/**
29 * A set of routes for a particular prefix in a route table.
30 */
31public class RouteSet {
32 private final RouteTableId tableId;
33
34 private final IpPrefix prefix;
35 private final Set<Route> routes;
36
37 /**
38 * Creates a new route set.
39 *
40 * @param tableId route table ID
41 * @param prefix IP prefix
42 * @param routes routes for the given prefix
43 */
44 public RouteSet(RouteTableId tableId, IpPrefix prefix, Set<Route> routes) {
45 this.tableId = checkNotNull(tableId);
46 this.prefix = checkNotNull(prefix);
47 this.routes = ImmutableSet.copyOf(checkNotNull(routes));
48 }
49
50 /**
51 * Returns the route table ID.
52 *
53 * @return route table ID
54 */
55 public RouteTableId tableId() {
56 return tableId;
57 }
58
59 /**
60 * Returns the IP prefix.
61 *
62 * @return IP prefix
63 */
64 public IpPrefix prefix() {
65 return prefix;
66 }
67
68 /**
69 * Returns the set of routes.
70 *
71 * @return routes
72 */
73 public Set<Route> routes() {
74 return routes;
75 }
76
77 @Override
78 public int hashCode() {
79 return Objects.hash(tableId, prefix, routes);
80 }
81
82 @Override
83 public boolean equals(Object other) {
84 if (this == other) {
85 return true;
86 }
87
88 if (!(other instanceof RouteSet)) {
89 return false;
90 }
91
92 RouteSet that = (RouteSet) other;
93
94 return Objects.equals(this.tableId, that.tableId) &&
95 Objects.equals(this.prefix, that.prefix) &&
96 Objects.equals(this.routes, that.routes);
97 }
Charles Chan50f3f132018-06-21 17:41:50 -070098
99 @Override
100 public String toString() {
101 return MoreObjects.toStringHelper(RouteSet.class)
102 .add("tableId", tableId)
103 .add("prefix", prefix)
104 .add("routes", routes)
105 .toString();
106 }
Jonathan Hart96c146b2017-02-24 16:32:00 -0800107}