blob: bac3d713bbca0d738a5bb147e0ecf7b8c4a1e35b [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.
26 */
27public class RouteUpdate {
28 private final Type type; // The route update type
29 private final RouteEntry routeEntry; // The updated route entry
30
31 /**
32 * Specifies the type of a route update.
Thomas Vachuska4b420772014-10-30 16:46:17 -070033 * <p>
Jonathan Hart335ef462014-10-16 08:20:46 -070034 * Route updates can either provide updated information for a route, or
35 * withdraw a previously updated route.
Thomas Vachuska4b420772014-10-30 16:46:17 -070036 * </p>
Jonathan Hart335ef462014-10-16 08:20:46 -070037 */
38 public enum Type {
39 /**
40 * The update contains updated route information for a route.
41 */
42 UPDATE,
43 /**
44 * The update withdraws the route, meaning any previous information is
45 * no longer valid.
46 */
47 DELETE
48 }
49
50 /**
51 * Class constructor.
52 *
53 * @param type the type of the route update
54 * @param routeEntry the route entry with the update
55 */
56 public RouteUpdate(Type type, RouteEntry routeEntry) {
57 this.type = type;
58 this.routeEntry = checkNotNull(routeEntry);
59 }
60
61 /**
62 * Returns the type of the route update.
63 *
64 * @return the type of the update
65 */
66 public Type type() {
67 return type;
68 }
69
70 /**
71 * Returns the route entry the route update is for.
72 *
73 * @return the route entry the route update is for
74 */
75 public RouteEntry routeEntry() {
76 return routeEntry;
77 }
78
79 @Override
80 public boolean equals(Object other) {
81 if (other == this) {
82 return true;
83 }
84
85 if (!(other instanceof RouteUpdate)) {
86 return false;
87 }
88
89 RouteUpdate otherUpdate = (RouteUpdate) other;
90
91 return Objects.equals(this.type, otherUpdate.type) &&
92 Objects.equals(this.routeEntry, otherUpdate.routeEntry);
93 }
94
95 @Override
96 public int hashCode() {
97 return Objects.hash(type, routeEntry);
98 }
99
100 @Override
101 public String toString() {
102 return MoreObjects.toStringHelper(getClass())
103 .add("type", type)
104 .add("routeEntry", routeEntry)
105 .toString();
106 }
107}