blob: 855fac4611550c6cb127a161762176ed53740b76 [file] [log] [blame]
Jonathan Hart7d7e2f52016-03-29 16:22:49 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Jonathan Hart7d7e2f52016-03-29 16:22:49 -07003 *
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
Ray Milkey69ec8712017-08-08 13:00:43 -070017package org.onosproject.routeservice;
Jonathan Hart7d7e2f52016-03-29 16:22:49 -070018
19import org.onlab.packet.IpAddress;
20import org.onlab.packet.IpPrefix;
21import org.onlab.packet.MacAddress;
Charles Chan92ca94d2017-03-17 18:05:22 -070022import org.onlab.packet.VlanId;
Jonathan Hart7d7e2f52016-03-29 16:22:49 -070023
Jonathan Hart6c2e7962016-04-11 13:54:09 -070024import java.util.Objects;
25
Jonathan Hartfd176612016-04-11 10:42:10 -070026import static com.google.common.base.MoreObjects.toStringHelper;
27
Jonathan Hart7d7e2f52016-03-29 16:22:49 -070028/**
29 * Represents a route with the next hop MAC address resolved.
30 */
Charles Chan9640c812017-08-23 13:55:39 -070031// TODO Remove location from ResolvedRoute
Jonathan Hart7d7e2f52016-03-29 16:22:49 -070032public class ResolvedRoute {
33
Jonathan Hartf2e7a342017-03-20 15:43:21 -070034 private final Route route;
Jonathan Hart7d7e2f52016-03-29 16:22:49 -070035 private final MacAddress nextHopMac;
Charles Chan92ca94d2017-03-17 18:05:22 -070036 private final VlanId nextHopVlan;
Charles Chan9640c812017-08-23 13:55:39 -070037
38 /**
39 * Creates a new resolved route.
40 *
41 * @param route input route
42 * @param nextHopMac next hop MAC address
43 */
44 public ResolvedRoute(Route route, MacAddress nextHopMac) {
45 this(route, nextHopMac, VlanId.NONE);
46 }
47
48 /**
49 * Creates a new resolved route.
50 *
51 * @param route input route
52 * @param nextHopMac next hop MAC address
53 * @param nextHopVlan next hop VLAN ID
54 */
55 public ResolvedRoute(Route route, MacAddress nextHopMac, VlanId nextHopVlan) {
56 this.route = route;
57 this.nextHopMac = nextHopMac;
58 this.nextHopVlan = nextHopVlan;
Charles Chan9640c812017-08-23 13:55:39 -070059 }
60
Charles Chan92ca94d2017-03-17 18:05:22 -070061 /**
Jonathan Hartf2e7a342017-03-20 15:43:21 -070062 * Returns the original route.
Charles Chan92ca94d2017-03-17 18:05:22 -070063 *
Jonathan Hartf2e7a342017-03-20 15:43:21 -070064 * @return route
Charles Chan92ca94d2017-03-17 18:05:22 -070065 */
Jonathan Hartf2e7a342017-03-20 15:43:21 -070066 public Route route() {
67 return route;
Jonathan Hart7d7e2f52016-03-29 16:22:49 -070068 }
69
70 /**
71 * Returns the IP prefix.
72 *
73 * @return IP prefix
74 */
75 public IpPrefix prefix() {
Jonathan Hartf2e7a342017-03-20 15:43:21 -070076 return route.prefix();
Jonathan Hart7d7e2f52016-03-29 16:22:49 -070077 }
78
79 /**
80 * Returns the next hop IP address.
81 *
82 * @return IP address
83 */
84 public IpAddress nextHop() {
Jonathan Hartf2e7a342017-03-20 15:43:21 -070085 return route.nextHop();
Jonathan Hart7d7e2f52016-03-29 16:22:49 -070086 }
87
88 /**
89 * Returns the next hop MAC address.
90 *
91 * @return MAC address
92 */
93 public MacAddress nextHopMac() {
94 return nextHopMac;
95 }
Jonathan Hartfd176612016-04-11 10:42:10 -070096
Charles Chan8fe9f4c2016-10-24 16:46:25 -070097 /**
Charles Chan92ca94d2017-03-17 18:05:22 -070098 * Returns the next hop VLAN ID.
99 *
100 * @return VLAN ID
101 */
102 public VlanId nextHopVlan() {
103 return nextHopVlan;
104 }
105
Jonathan Hartfd176612016-04-11 10:42:10 -0700106 @Override
Jonathan Hart6c2e7962016-04-11 13:54:09 -0700107 public int hashCode() {
Charles Chan9bc60742017-11-19 13:59:59 -0800108 return Objects.hash(route, nextHopMac, nextHopVlan);
Jonathan Hart6c2e7962016-04-11 13:54:09 -0700109 }
110
111 @Override
112 public boolean equals(Object other) {
113 if (this == other) {
114 return true;
115 }
116
117 if (!(other instanceof ResolvedRoute)) {
118 return false;
119 }
120
121 ResolvedRoute that = (ResolvedRoute) other;
122
Jonathan Hartf2e7a342017-03-20 15:43:21 -0700123 return Objects.equals(this.route, that.route) &&
Charles Chan8fe9f4c2016-10-24 16:46:25 -0700124 Objects.equals(this.nextHopMac, that.nextHopMac) &&
Charles Chan9bc60742017-11-19 13:59:59 -0800125 Objects.equals(this.nextHopVlan, that.nextHopVlan);
Jonathan Hart6c2e7962016-04-11 13:54:09 -0700126 }
127
128 @Override
Jonathan Hartfd176612016-04-11 10:42:10 -0700129 public String toString() {
130 return toStringHelper(this)
Jonathan Hartf2e7a342017-03-20 15:43:21 -0700131 .add("route", route)
Jonathan Hartfd176612016-04-11 10:42:10 -0700132 .add("nextHopMac", nextHopMac)
Charles Chan92ca94d2017-03-17 18:05:22 -0700133 .add("nextHopVlan", nextHopVlan)
Jonathan Hartfd176612016-04-11 10:42:10 -0700134 .toString();
135 }
Jonathan Hart7d7e2f52016-03-29 16:22:49 -0700136}