Jonathan Hart | 335ef46 | 2014-10-16 08:20:46 -0700 | [diff] [blame] | 1 | package org.onlab.onos.sdnip; |
| 2 | |
| 3 | import static com.google.common.base.Preconditions.checkNotNull; |
| 4 | |
| 5 | import java.util.Objects; |
| 6 | |
| 7 | import com.google.common.base.MoreObjects; |
| 8 | |
| 9 | /** |
| 10 | * Represents a change in routing information. |
| 11 | */ |
| 12 | public class RouteUpdate { |
| 13 | private final Type type; // The route update type |
| 14 | private final RouteEntry routeEntry; // The updated route entry |
| 15 | |
| 16 | /** |
| 17 | * Specifies the type of a route update. |
| 18 | * <p/> |
| 19 | * Route updates can either provide updated information for a route, or |
| 20 | * withdraw a previously updated route. |
| 21 | */ |
| 22 | public enum Type { |
| 23 | /** |
| 24 | * The update contains updated route information for a route. |
| 25 | */ |
| 26 | UPDATE, |
| 27 | /** |
| 28 | * The update withdraws the route, meaning any previous information is |
| 29 | * no longer valid. |
| 30 | */ |
| 31 | DELETE |
| 32 | } |
| 33 | |
| 34 | /** |
| 35 | * Class constructor. |
| 36 | * |
| 37 | * @param type the type of the route update |
| 38 | * @param routeEntry the route entry with the update |
| 39 | */ |
| 40 | public RouteUpdate(Type type, RouteEntry routeEntry) { |
| 41 | this.type = type; |
| 42 | this.routeEntry = checkNotNull(routeEntry); |
| 43 | } |
| 44 | |
| 45 | /** |
| 46 | * Returns the type of the route update. |
| 47 | * |
| 48 | * @return the type of the update |
| 49 | */ |
| 50 | public Type type() { |
| 51 | return type; |
| 52 | } |
| 53 | |
| 54 | /** |
| 55 | * Returns the route entry the route update is for. |
| 56 | * |
| 57 | * @return the route entry the route update is for |
| 58 | */ |
| 59 | public RouteEntry routeEntry() { |
| 60 | return routeEntry; |
| 61 | } |
| 62 | |
| 63 | @Override |
| 64 | public boolean equals(Object other) { |
| 65 | if (other == this) { |
| 66 | return true; |
| 67 | } |
| 68 | |
| 69 | if (!(other instanceof RouteUpdate)) { |
| 70 | return false; |
| 71 | } |
| 72 | |
| 73 | RouteUpdate otherUpdate = (RouteUpdate) other; |
| 74 | |
| 75 | return Objects.equals(this.type, otherUpdate.type) && |
| 76 | Objects.equals(this.routeEntry, otherUpdate.routeEntry); |
| 77 | } |
| 78 | |
| 79 | @Override |
| 80 | public int hashCode() { |
| 81 | return Objects.hash(type, routeEntry); |
| 82 | } |
| 83 | |
| 84 | @Override |
| 85 | public String toString() { |
| 86 | return MoreObjects.toStringHelper(getClass()) |
| 87 | .add("type", type) |
| 88 | .add("routeEntry", routeEntry) |
| 89 | .toString(); |
| 90 | } |
| 91 | } |