blob: 0d52c8b048bdae2c798121906967a8ba49c64c80 [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;
Charles Chan8fe9f4c2016-10-24 16:46:25 -070023import org.onosproject.net.ConnectPoint;
Jonathan Hart7d7e2f52016-03-29 16:22:49 -070024
Jonathan Hart6c2e7962016-04-11 13:54:09 -070025import java.util.Objects;
26
Jonathan Hartfd176612016-04-11 10:42:10 -070027import static com.google.common.base.MoreObjects.toStringHelper;
28
Jonathan Hart7d7e2f52016-03-29 16:22:49 -070029/**
30 * Represents a route with the next hop MAC address resolved.
31 */
Charles Chan9640c812017-08-23 13:55:39 -070032// TODO Remove location from ResolvedRoute
Jonathan Hart7d7e2f52016-03-29 16:22:49 -070033public class ResolvedRoute {
34
Jonathan Hartf2e7a342017-03-20 15:43:21 -070035 private final Route route;
Jonathan Hart7d7e2f52016-03-29 16:22:49 -070036 private final MacAddress nextHopMac;
Charles Chan92ca94d2017-03-17 18:05:22 -070037 private final VlanId nextHopVlan;
Charles Chan8fe9f4c2016-10-24 16:46:25 -070038 private final ConnectPoint location;
Jonathan Hart7d7e2f52016-03-29 16:22:49 -070039
40 /**
41 * Creates a new resolved route.
42 *
43 * @param route input route
44 * @param nextHopMac next hop MAC address
Charles Chan8fe9f4c2016-10-24 16:46:25 -070045 * @param location connect point where the next hop connects to
Charles Chan9640c812017-08-23 13:55:39 -070046 * @deprecated in 1.11 ("Loon")
Jonathan Hart7d7e2f52016-03-29 16:22:49 -070047 */
Charles Chan9640c812017-08-23 13:55:39 -070048 @Deprecated
Charles Chan8fe9f4c2016-10-24 16:46:25 -070049 public ResolvedRoute(Route route, MacAddress nextHopMac, ConnectPoint location) {
Charles Chan92ca94d2017-03-17 18:05:22 -070050 this(route, nextHopMac, VlanId.NONE, location);
Jonathan Hart7d7e2f52016-03-29 16:22:49 -070051 }
52
53 /**
54 * Creates a new resolved route.
55 *
Charles Chan92ca94d2017-03-17 18:05:22 -070056 * @param route input route
57 * @param nextHopMac next hop MAC address
58 * @param nextHopVlan next hop VLAN ID
59 * @param location connect point where the next hop connects to
Charles Chan9640c812017-08-23 13:55:39 -070060 * @deprecated in 1.11 ("Loon")
Charles Chan92ca94d2017-03-17 18:05:22 -070061 */
Charles Chan9640c812017-08-23 13:55:39 -070062 @Deprecated
Charles Chan92ca94d2017-03-17 18:05:22 -070063 public ResolvedRoute(Route route, MacAddress nextHopMac, VlanId nextHopVlan,
64 ConnectPoint location) {
Jonathan Hartf2e7a342017-03-20 15:43:21 -070065 this.route = route;
Charles Chan92ca94d2017-03-17 18:05:22 -070066 this.nextHopMac = nextHopMac;
67 this.nextHopVlan = nextHopVlan;
68 this.location = location;
69 }
70
Charles Chan9640c812017-08-23 13:55:39 -070071
72 /**
73 * Creates a new resolved route.
74 *
75 * @param route input route
76 * @param nextHopMac next hop MAC address
77 */
78 public ResolvedRoute(Route route, MacAddress nextHopMac) {
79 this(route, nextHopMac, VlanId.NONE);
80 }
81
82 /**
83 * Creates a new resolved route.
84 *
85 * @param route input route
86 * @param nextHopMac next hop MAC address
87 * @param nextHopVlan next hop VLAN ID
88 */
89 public ResolvedRoute(Route route, MacAddress nextHopMac, VlanId nextHopVlan) {
90 this.route = route;
91 this.nextHopMac = nextHopMac;
92 this.nextHopVlan = nextHopVlan;
93 this.location = null;
94 }
95
Charles Chan92ca94d2017-03-17 18:05:22 -070096 /**
Jonathan Hartf2e7a342017-03-20 15:43:21 -070097 * Returns the original route.
Charles Chan92ca94d2017-03-17 18:05:22 -070098 *
Jonathan Hartf2e7a342017-03-20 15:43:21 -070099 * @return route
Charles Chan92ca94d2017-03-17 18:05:22 -0700100 */
Jonathan Hartf2e7a342017-03-20 15:43:21 -0700101 public Route route() {
102 return route;
Jonathan Hart7d7e2f52016-03-29 16:22:49 -0700103 }
104
105 /**
106 * Returns the IP prefix.
107 *
108 * @return IP prefix
109 */
110 public IpPrefix prefix() {
Jonathan Hartf2e7a342017-03-20 15:43:21 -0700111 return route.prefix();
Jonathan Hart7d7e2f52016-03-29 16:22:49 -0700112 }
113
114 /**
115 * Returns the next hop IP address.
116 *
117 * @return IP address
118 */
119 public IpAddress nextHop() {
Jonathan Hartf2e7a342017-03-20 15:43:21 -0700120 return route.nextHop();
Jonathan Hart7d7e2f52016-03-29 16:22:49 -0700121 }
122
123 /**
124 * Returns the next hop MAC address.
125 *
126 * @return MAC address
127 */
128 public MacAddress nextHopMac() {
129 return nextHopMac;
130 }
Jonathan Hartfd176612016-04-11 10:42:10 -0700131
Charles Chan8fe9f4c2016-10-24 16:46:25 -0700132 /**
Charles Chan92ca94d2017-03-17 18:05:22 -0700133 * Returns the next hop VLAN ID.
134 *
135 * @return VLAN ID
136 */
137 public VlanId nextHopVlan() {
138 return nextHopVlan;
139 }
140
141 /**
Charles Chan8fe9f4c2016-10-24 16:46:25 -0700142 * Returns the next hop location.
143 *
144 * @return connect point where the next hop attaches to
Charles Chan9640c812017-08-23 13:55:39 -0700145 * @deprecated in 1.11 ("Loon")
Charles Chan8fe9f4c2016-10-24 16:46:25 -0700146 */
Charles Chan9640c812017-08-23 13:55:39 -0700147 @Deprecated
Charles Chan8fe9f4c2016-10-24 16:46:25 -0700148 public ConnectPoint location() {
149 return location;
150 }
151
Jonathan Hartfd176612016-04-11 10:42:10 -0700152 @Override
Jonathan Hart6c2e7962016-04-11 13:54:09 -0700153 public int hashCode() {
Charles Chan9bc60742017-11-19 13:59:59 -0800154 return Objects.hash(route, nextHopMac, nextHopVlan);
Jonathan Hart6c2e7962016-04-11 13:54:09 -0700155 }
156
157 @Override
158 public boolean equals(Object other) {
159 if (this == other) {
160 return true;
161 }
162
163 if (!(other instanceof ResolvedRoute)) {
164 return false;
165 }
166
167 ResolvedRoute that = (ResolvedRoute) other;
168
Jonathan Hartf2e7a342017-03-20 15:43:21 -0700169 return Objects.equals(this.route, that.route) &&
Charles Chan8fe9f4c2016-10-24 16:46:25 -0700170 Objects.equals(this.nextHopMac, that.nextHopMac) &&
Charles Chan9bc60742017-11-19 13:59:59 -0800171 Objects.equals(this.nextHopVlan, that.nextHopVlan);
Jonathan Hart6c2e7962016-04-11 13:54:09 -0700172 }
173
174 @Override
Jonathan Hartfd176612016-04-11 10:42:10 -0700175 public String toString() {
176 return toStringHelper(this)
Jonathan Hartf2e7a342017-03-20 15:43:21 -0700177 .add("route", route)
Jonathan Hartfd176612016-04-11 10:42:10 -0700178 .add("nextHopMac", nextHopMac)
Charles Chan92ca94d2017-03-17 18:05:22 -0700179 .add("nextHopVlan", nextHopVlan)
Jonathan Hartfd176612016-04-11 10:42:10 -0700180 .toString();
181 }
Jonathan Hart7d7e2f52016-03-29 16:22:49 -0700182}