blob: 68e43dc64aa76ae4af0e7dee29320a2be2044e6b [file] [log] [blame]
Thomas Vachuska781d18b2014-10-27 10:31:25 -07001/*
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07002 * Copyright 2014 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 Hart335ef462014-10-16 08:20:46 -070016package org.onlab.onos.sdnip;
17
18import static com.google.common.base.Preconditions.checkNotNull;
19
20import java.util.Objects;
21
22import com.google.common.base.MoreObjects;
23
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.
33 * <p/>
34 * Route updates can either provide updated information for a route, or
35 * withdraw a previously updated route.
36 */
37 public enum Type {
38 /**
39 * The update contains updated route information for a route.
40 */
41 UPDATE,
42 /**
43 * The update withdraws the route, meaning any previous information is
44 * no longer valid.
45 */
46 DELETE
47 }
48
49 /**
50 * Class constructor.
51 *
52 * @param type the type of the route update
53 * @param routeEntry the route entry with the update
54 */
55 public RouteUpdate(Type type, RouteEntry routeEntry) {
56 this.type = type;
57 this.routeEntry = checkNotNull(routeEntry);
58 }
59
60 /**
61 * Returns the type of the route update.
62 *
63 * @return the type of the update
64 */
65 public Type type() {
66 return type;
67 }
68
69 /**
70 * Returns the route entry the route update is for.
71 *
72 * @return the route entry the route update is for
73 */
74 public RouteEntry routeEntry() {
75 return routeEntry;
76 }
77
78 @Override
79 public boolean equals(Object other) {
80 if (other == this) {
81 return true;
82 }
83
84 if (!(other instanceof RouteUpdate)) {
85 return false;
86 }
87
88 RouteUpdate otherUpdate = (RouteUpdate) other;
89
90 return Objects.equals(this.type, otherUpdate.type) &&
91 Objects.equals(this.routeEntry, otherUpdate.routeEntry);
92 }
93
94 @Override
95 public int hashCode() {
96 return Objects.hash(type, routeEntry);
97 }
98
99 @Override
100 public String toString() {
101 return MoreObjects.toStringHelper(getClass())
102 .add("type", type)
103 .add("routeEntry", routeEntry)
104 .toString();
105 }
106}