Mohammad Shahid | aa7c123 | 2017-08-09 11:13:15 +0530 | [diff] [blame] | 1 | /* |
| 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 | |
Ray Milkey | a95193c | 2017-08-10 15:35:36 -0700 | [diff] [blame] | 17 | package org.onosproject.evpnrouteservice; |
Mohammad Shahid | aa7c123 | 2017-08-09 11:13:15 +0530 | [diff] [blame] | 18 | |
| 19 | import java.util.Objects; |
| 20 | import java.util.Set; |
| 21 | |
Ray Milkey | a95193c | 2017-08-10 15:35:36 -0700 | [diff] [blame] | 22 | import com.google.common.collect.ImmutableSet; |
| 23 | |
Mohammad Shahid | aa7c123 | 2017-08-09 11:13:15 +0530 | [diff] [blame] | 24 | import static com.google.common.base.Preconditions.checkNotNull; |
| 25 | |
| 26 | /** |
| 27 | * A set of routes for a particular prefix in a route table. |
| 28 | */ |
| 29 | public class EvpnRouteSet { |
Jonathan Hart | e9c0c6e | 2017-08-09 16:44:13 -0700 | [diff] [blame] | 30 | private final EvpnRouteTableId tableId; |
Mohammad Shahid | aa7c123 | 2017-08-09 11:13:15 +0530 | [diff] [blame] | 31 | |
| 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 Hart | e9c0c6e | 2017-08-09 16:44:13 -0700 | [diff] [blame] | 42 | public EvpnRouteSet(EvpnRouteTableId tableId, EvpnPrefix prefix, Set<EvpnRoute> |
Mohammad Shahid | aa7c123 | 2017-08-09 11:13:15 +0530 | [diff] [blame] | 43 | 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 Hart | e9c0c6e | 2017-08-09 16:44:13 -0700 | [diff] [blame] | 54 | public EvpnRouteTableId tableId() { |
Mohammad Shahid | aa7c123 | 2017-08-09 11:13:15 +0530 | [diff] [blame] | 55 | 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 Hart | e9c0c6e | 2017-08-09 16:44:13 -0700 | [diff] [blame] | 87 | if (!(other instanceof EvpnRouteSet)) { |
Mohammad Shahid | aa7c123 | 2017-08-09 11:13:15 +0530 | [diff] [blame] | 88 | 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 | } |