Jonathan Hart | 96c146b | 2017-02-24 16:32:00 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2017-present Open Networking Foundation |
Jonathan Hart | 96c146b | 2017-02-24 16:32:00 -0800 | [diff] [blame] | 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 | |
Ray Milkey | 69ec871 | 2017-08-08 13:00:43 -0700 | [diff] [blame] | 17 | package org.onosproject.routeservice; |
Jonathan Hart | 96c146b | 2017-02-24 16:32:00 -0800 | [diff] [blame] | 18 | |
Charles Chan | 93888fb | 2018-06-21 17:41:50 -0700 | [diff] [blame] | 19 | import com.google.common.base.MoreObjects; |
Jonathan Hart | 96c146b | 2017-02-24 16:32:00 -0800 | [diff] [blame] | 20 | import com.google.common.collect.ImmutableSet; |
| 21 | import org.onlab.packet.IpPrefix; |
| 22 | |
| 23 | import java.util.Objects; |
| 24 | import java.util.Set; |
| 25 | |
| 26 | import static com.google.common.base.Preconditions.checkNotNull; |
| 27 | |
| 28 | /** |
| 29 | * A set of routes for a particular prefix in a route table. |
| 30 | */ |
| 31 | public 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 Chan | 93888fb | 2018-06-21 17:41:50 -0700 | [diff] [blame] | 98 | |
| 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 Hart | 96c146b | 2017-02-24 16:32:00 -0800 | [diff] [blame] | 107 | } |