Thomas Vachuska | 781d18b | 2014-10-27 10:31:25 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Laboratory |
Thomas Vachuska | 781d18b | 2014-10-27 10:31:25 -0700 | [diff] [blame] | 3 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 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 |
Thomas Vachuska | 781d18b | 2014-10-27 10:31:25 -0700 | [diff] [blame] | 7 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 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. |
Thomas Vachuska | 781d18b | 2014-10-27 10:31:25 -0700 | [diff] [blame] | 15 | */ |
Jonathan Hart | 2da1e60 | 2015-02-18 19:09:24 -0800 | [diff] [blame] | 16 | package org.onosproject.routing; |
Jonathan Hart | 335ef46 | 2014-10-16 08:20:46 -0700 | [diff] [blame] | 17 | |
Jonathan Hart | 41349e9 | 2015-02-09 14:14:02 -0800 | [diff] [blame] | 18 | import com.google.common.base.MoreObjects; |
Jonathan Hart | 335ef46 | 2014-10-16 08:20:46 -0700 | [diff] [blame] | 19 | |
| 20 | import java.util.Objects; |
| 21 | |
Jonathan Hart | 41349e9 | 2015-02-09 14:14:02 -0800 | [diff] [blame] | 22 | import static com.google.common.base.Preconditions.checkNotNull; |
Jonathan Hart | 335ef46 | 2014-10-16 08:20:46 -0700 | [diff] [blame] | 23 | |
| 24 | /** |
| 25 | * Represents a change in routing information. |
Jonathan Hart | 888eaa0 | 2016-06-22 15:56:21 -0700 | [diff] [blame] | 26 | * |
| 27 | * @deprecated use RouteService instead |
Jonathan Hart | 335ef46 | 2014-10-16 08:20:46 -0700 | [diff] [blame] | 28 | */ |
Jonathan Hart | 888eaa0 | 2016-06-22 15:56:21 -0700 | [diff] [blame] | 29 | @Deprecated |
Jonathan Hart | 335ef46 | 2014-10-16 08:20:46 -0700 | [diff] [blame] | 30 | public class RouteUpdate { |
| 31 | private final Type type; // The route update type |
| 32 | private final RouteEntry routeEntry; // The updated route entry |
| 33 | |
| 34 | /** |
| 35 | * Specifies the type of a route update. |
Thomas Vachuska | 4b42077 | 2014-10-30 16:46:17 -0700 | [diff] [blame] | 36 | * <p> |
Jonathan Hart | 335ef46 | 2014-10-16 08:20:46 -0700 | [diff] [blame] | 37 | * Route updates can either provide updated information for a route, or |
| 38 | * withdraw a previously updated route. |
Thomas Vachuska | 4b42077 | 2014-10-30 16:46:17 -0700 | [diff] [blame] | 39 | * </p> |
Jonathan Hart | 335ef46 | 2014-10-16 08:20:46 -0700 | [diff] [blame] | 40 | */ |
| 41 | public enum Type { |
| 42 | /** |
| 43 | * The update contains updated route information for a route. |
| 44 | */ |
| 45 | UPDATE, |
| 46 | /** |
| 47 | * The update withdraws the route, meaning any previous information is |
| 48 | * no longer valid. |
| 49 | */ |
| 50 | DELETE |
| 51 | } |
| 52 | |
| 53 | /** |
| 54 | * Class constructor. |
| 55 | * |
| 56 | * @param type the type of the route update |
| 57 | * @param routeEntry the route entry with the update |
| 58 | */ |
| 59 | public RouteUpdate(Type type, RouteEntry routeEntry) { |
| 60 | this.type = type; |
| 61 | this.routeEntry = checkNotNull(routeEntry); |
| 62 | } |
| 63 | |
| 64 | /** |
| 65 | * Returns the type of the route update. |
| 66 | * |
| 67 | * @return the type of the update |
| 68 | */ |
| 69 | public Type type() { |
| 70 | return type; |
| 71 | } |
| 72 | |
| 73 | /** |
| 74 | * Returns the route entry the route update is for. |
| 75 | * |
| 76 | * @return the route entry the route update is for |
| 77 | */ |
| 78 | public RouteEntry routeEntry() { |
| 79 | return routeEntry; |
| 80 | } |
| 81 | |
| 82 | @Override |
| 83 | public boolean equals(Object other) { |
| 84 | if (other == this) { |
| 85 | return true; |
| 86 | } |
| 87 | |
| 88 | if (!(other instanceof RouteUpdate)) { |
| 89 | return false; |
| 90 | } |
| 91 | |
| 92 | RouteUpdate otherUpdate = (RouteUpdate) other; |
| 93 | |
| 94 | return Objects.equals(this.type, otherUpdate.type) && |
| 95 | Objects.equals(this.routeEntry, otherUpdate.routeEntry); |
| 96 | } |
| 97 | |
| 98 | @Override |
| 99 | public int hashCode() { |
| 100 | return Objects.hash(type, routeEntry); |
| 101 | } |
| 102 | |
| 103 | @Override |
| 104 | public String toString() { |
| 105 | return MoreObjects.toStringHelper(getClass()) |
| 106 | .add("type", type) |
| 107 | .add("routeEntry", routeEntry) |
| 108 | .toString(); |
| 109 | } |
| 110 | } |