blob: 3b1fa7b1f673254e336bd69d5dc74508f8c5247b [file] [log] [blame]
Thomas Vachuska781d18b2014-10-27 10:31:25 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2017-present Open Networking Foundation
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 Hartf4bd0482017-01-27 15:11:18 -080016
Jonathan Hartc9e36c52017-01-05 09:53:33 +130017package org.onosproject.routing.bgp;
Jonathan Hart335ef462014-10-16 08:20:46 -070018
Jonathan Hart41349e92015-02-09 14:14:02 -080019import com.google.common.base.MoreObjects;
Jonathan Hart335ef462014-10-16 08:20:46 -070020
21import java.util.Objects;
22
Jonathan Hart41349e92015-02-09 14:14:02 -080023import static com.google.common.base.Preconditions.checkNotNull;
Jonathan Hart335ef462014-10-16 08:20:46 -070024
25/**
26 * Represents a change in routing information.
27 */
28public class RouteUpdate {
29 private final Type type; // The route update type
30 private final RouteEntry routeEntry; // The updated route entry
31
32 /**
33 * Specifies the type of a route update.
Thomas Vachuska4b420772014-10-30 16:46:17 -070034 * <p>
Jonathan Hart335ef462014-10-16 08:20:46 -070035 * Route updates can either provide updated information for a route, or
36 * withdraw a previously updated route.
Thomas Vachuska4b420772014-10-30 16:46:17 -070037 * </p>
Jonathan Hart335ef462014-10-16 08:20:46 -070038 */
39 public enum Type {
40 /**
41 * The update contains updated route information for a route.
42 */
43 UPDATE,
44 /**
45 * The update withdraws the route, meaning any previous information is
46 * no longer valid.
47 */
48 DELETE
49 }
50
51 /**
52 * Class constructor.
53 *
54 * @param type the type of the route update
55 * @param routeEntry the route entry with the update
56 */
57 public RouteUpdate(Type type, RouteEntry routeEntry) {
58 this.type = type;
59 this.routeEntry = checkNotNull(routeEntry);
60 }
61
62 /**
63 * Returns the type of the route update.
64 *
65 * @return the type of the update
66 */
67 public Type type() {
68 return type;
69 }
70
71 /**
72 * Returns the route entry the route update is for.
73 *
74 * @return the route entry the route update is for
75 */
76 public RouteEntry routeEntry() {
77 return routeEntry;
78 }
79
80 @Override
81 public boolean equals(Object other) {
82 if (other == this) {
83 return true;
84 }
85
86 if (!(other instanceof RouteUpdate)) {
87 return false;
88 }
89
90 RouteUpdate otherUpdate = (RouteUpdate) other;
91
92 return Objects.equals(this.type, otherUpdate.type) &&
93 Objects.equals(this.routeEntry, otherUpdate.routeEntry);
94 }
95
96 @Override
97 public int hashCode() {
98 return Objects.hash(type, routeEntry);
99 }
100
101 @Override
102 public String toString() {
103 return MoreObjects.toStringHelper(getClass())
104 .add("type", type)
105 .add("routeEntry", routeEntry)
106 .toString();
107 }
108}