blob: c970681897287d66daff1ec210b029a81ebae118 [file] [log] [blame]
Jonathan Hart96c146b2017-02-24 16:32:00 -08001/*
2 * Copyright 2017-present Open Networking Laboratory
3 *
4 * 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
7 *
8 * 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.
15 */
16
17package org.onosproject.incubator.net.routing;
18
19import com.google.common.annotations.Beta;
20import org.onlab.packet.IpPrefix;
21
22import java.util.Objects;
23import java.util.Optional;
24import java.util.Set;
25
26import static com.google.common.base.Preconditions.checkNotNull;
27
28/**
29 * Routing information for a given prefix.
30 */
31@Beta
32public class RouteInfo {
33
34 private final IpPrefix prefix;
35 private final ResolvedRoute bestRoute;
36 private final Set<ResolvedRoute> allRoutes;
37
38 /**
39 * Creates a new route info object.
40 *
41 * @param prefix IP prefix
42 * @param bestRoute best route for this prefix if one exists
43 * @param allRoutes all known routes for this prefix
44 */
45 @Beta
46 public RouteInfo(IpPrefix prefix, ResolvedRoute bestRoute, Set<ResolvedRoute> allRoutes) {
47 this.prefix = checkNotNull(prefix);
48 this.bestRoute = bestRoute;
49 this.allRoutes = checkNotNull(allRoutes);
50 }
51
52 /**
53 * Returns the IP prefix.
54 *
55 * @return IP prefix
56 */
57 public IpPrefix prefix() {
58 return prefix;
59 }
60
61 /**
62 * Returns the best route for this prefix if one exists.
63 *
64 * @return optional best route
65 */
66 public Optional<ResolvedRoute> bestRoute() {
67 return Optional.ofNullable(bestRoute);
68 }
69
70 /**
71 * Returns all routes for this prefix.
72 *
73 * @return all routes
74 */
75 public Set<ResolvedRoute> allRoutes() {
76 return allRoutes;
77 }
78
79 @Override
80 public int hashCode() {
81 return Objects.hash(prefix, bestRoute, allRoutes);
82 }
83
84 @Override
85 public boolean equals(Object other) {
86 if (this == other) {
87 return true;
88 }
89
90 if (!(other instanceof RouteInfo)) {
91 return false;
92 }
93
94 RouteInfo that = (RouteInfo) other;
95
96 return Objects.equals(this.prefix, that.prefix) &&
97 Objects.equals(this.bestRoute, that.bestRoute) &&
98 Objects.equals(this.allRoutes, that.allRoutes);
99 }
100}