blob: 61e8ac89a4eacba37465387d6ddf65573796a8ee [file] [log] [blame]
Thomas Vachuska781d18b2014-10-27 10:31:25 -07001/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
Jonathan Hart335ef462014-10-16 08:20:46 -070019package org.onlab.onos.sdnip;
20
21import static com.google.common.base.Preconditions.checkNotNull;
22
23import java.util.Objects;
24
25import com.google.common.base.MoreObjects;
26
27/**
28 * Represents a change in routing information.
29 */
30public 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.
36 * <p/>
37 * Route updates can either provide updated information for a route, or
38 * withdraw a previously updated route.
39 */
40 public enum Type {
41 /**
42 * The update contains updated route information for a route.
43 */
44 UPDATE,
45 /**
46 * The update withdraws the route, meaning any previous information is
47 * no longer valid.
48 */
49 DELETE
50 }
51
52 /**
53 * Class constructor.
54 *
55 * @param type the type of the route update
56 * @param routeEntry the route entry with the update
57 */
58 public RouteUpdate(Type type, RouteEntry routeEntry) {
59 this.type = type;
60 this.routeEntry = checkNotNull(routeEntry);
61 }
62
63 /**
64 * Returns the type of the route update.
65 *
66 * @return the type of the update
67 */
68 public Type type() {
69 return type;
70 }
71
72 /**
73 * Returns the route entry the route update is for.
74 *
75 * @return the route entry the route update is for
76 */
77 public RouteEntry routeEntry() {
78 return routeEntry;
79 }
80
81 @Override
82 public boolean equals(Object other) {
83 if (other == this) {
84 return true;
85 }
86
87 if (!(other instanceof RouteUpdate)) {
88 return false;
89 }
90
91 RouteUpdate otherUpdate = (RouteUpdate) other;
92
93 return Objects.equals(this.type, otherUpdate.type) &&
94 Objects.equals(this.routeEntry, otherUpdate.routeEntry);
95 }
96
97 @Override
98 public int hashCode() {
99 return Objects.hash(type, routeEntry);
100 }
101
102 @Override
103 public String toString() {
104 return MoreObjects.toStringHelper(getClass())
105 .add("type", type)
106 .add("routeEntry", routeEntry)
107 .toString();
108 }
109}