blob: 9f95f3b95560ec5df1baaf8e2684ef26c7e1dcd4 [file] [log] [blame]
Thomas Vachuska781d18b2014-10-27 10:31:25 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
Thomas Vachuska781d18b2014-10-27 10:31:25 -07003 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07004 * 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 Vachuska781d18b2014-10-27 10:31:25 -07007 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07008 * 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 Vachuska781d18b2014-10-27 10:31:25 -070015 */
Jonathan Hart2da1e602015-02-18 19:09:24 -080016package org.onosproject.routing;
Jonathan Hart335ef462014-10-16 08:20:46 -070017
Jonathan Hart41349e92015-02-09 14:14:02 -080018import com.google.common.base.MoreObjects;
Jonathan Hart335ef462014-10-16 08:20:46 -070019
20import java.util.Objects;
21
Jonathan Hart41349e92015-02-09 14:14:02 -080022import static com.google.common.base.Preconditions.checkNotNull;
Jonathan Hart335ef462014-10-16 08:20:46 -070023
24/**
25 * Represents a change in routing information.
Jonathan Hart888eaa02016-06-22 15:56:21 -070026 *
27 * @deprecated use RouteService instead
Jonathan Hart335ef462014-10-16 08:20:46 -070028 */
Jonathan Hart888eaa02016-06-22 15:56:21 -070029@Deprecated
Jonathan Hart335ef462014-10-16 08:20:46 -070030public 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 Vachuska4b420772014-10-30 16:46:17 -070036 * <p>
Jonathan Hart335ef462014-10-16 08:20:46 -070037 * Route updates can either provide updated information for a route, or
38 * withdraw a previously updated route.
Thomas Vachuska4b420772014-10-30 16:46:17 -070039 * </p>
Jonathan Hart335ef462014-10-16 08:20:46 -070040 */
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}