blob: 394e7641de6dc6563175fe6c612ad188dec73a45 [file] [log] [blame]
Jonathan Hart7d7e2f52016-03-29 16:22:49 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2016-present Open Networking Laboratory
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
17package org.onosproject.incubator.net.routing;
18
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 */
32public 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 Chan8fe9f4c2016-10-24 16:46:25 -070037 private final ConnectPoint location;
Jonathan Hart7d7e2f52016-03-29 16:22:49 -070038
39 /**
40 * Creates a new resolved route.
41 *
42 * @param route input route
43 * @param nextHopMac next hop MAC address
Charles Chan8fe9f4c2016-10-24 16:46:25 -070044 * @param location connect point where the next hop connects to
Jonathan Hart7d7e2f52016-03-29 16:22:49 -070045 */
Charles Chan8fe9f4c2016-10-24 16:46:25 -070046 public ResolvedRoute(Route route, MacAddress nextHopMac, ConnectPoint location) {
Charles Chan92ca94d2017-03-17 18:05:22 -070047 this(route, nextHopMac, VlanId.NONE, location);
Jonathan Hart7d7e2f52016-03-29 16:22:49 -070048 }
49
50 /**
51 * Creates a new resolved route.
52 *
Charles Chan92ca94d2017-03-17 18:05:22 -070053 * @param route input route
54 * @param nextHopMac next hop MAC address
55 * @param nextHopVlan next hop VLAN ID
56 * @param location connect point where the next hop connects to
57 */
58 public ResolvedRoute(Route route, MacAddress nextHopMac, VlanId nextHopVlan,
59 ConnectPoint location) {
Jonathan Hartf2e7a342017-03-20 15:43:21 -070060 this.route = route;
Charles Chan92ca94d2017-03-17 18:05:22 -070061 this.nextHopMac = nextHopMac;
62 this.nextHopVlan = nextHopVlan;
63 this.location = location;
64 }
65
66 /**
Jonathan Hartf2e7a342017-03-20 15:43:21 -070067 * Returns the original route.
Charles Chan92ca94d2017-03-17 18:05:22 -070068 *
Jonathan Hartf2e7a342017-03-20 15:43:21 -070069 * @return route
Charles Chan92ca94d2017-03-17 18:05:22 -070070 */
Jonathan Hartf2e7a342017-03-20 15:43:21 -070071 public Route route() {
72 return route;
Jonathan Hart7d7e2f52016-03-29 16:22:49 -070073 }
74
75 /**
76 * Returns the IP prefix.
77 *
78 * @return IP prefix
79 */
80 public IpPrefix prefix() {
Jonathan Hartf2e7a342017-03-20 15:43:21 -070081 return route.prefix();
Jonathan Hart7d7e2f52016-03-29 16:22:49 -070082 }
83
84 /**
85 * Returns the next hop IP address.
86 *
87 * @return IP address
88 */
89 public IpAddress nextHop() {
Jonathan Hartf2e7a342017-03-20 15:43:21 -070090 return route.nextHop();
Jonathan Hart7d7e2f52016-03-29 16:22:49 -070091 }
92
93 /**
94 * Returns the next hop MAC address.
95 *
96 * @return MAC address
97 */
98 public MacAddress nextHopMac() {
99 return nextHopMac;
100 }
Jonathan Hartfd176612016-04-11 10:42:10 -0700101
Charles Chan8fe9f4c2016-10-24 16:46:25 -0700102 /**
Charles Chan92ca94d2017-03-17 18:05:22 -0700103 * Returns the next hop VLAN ID.
104 *
105 * @return VLAN ID
106 */
107 public VlanId nextHopVlan() {
108 return nextHopVlan;
109 }
110
111 /**
Charles Chan8fe9f4c2016-10-24 16:46:25 -0700112 * Returns the next hop location.
113 *
114 * @return connect point where the next hop attaches to
115 */
116 public ConnectPoint location() {
117 return location;
118 }
119
Jonathan Hartfd176612016-04-11 10:42:10 -0700120 @Override
Jonathan Hart6c2e7962016-04-11 13:54:09 -0700121 public int hashCode() {
Jonathan Hartf2e7a342017-03-20 15:43:21 -0700122 return Objects.hash(route, nextHopMac, nextHopVlan, location);
Jonathan Hart6c2e7962016-04-11 13:54:09 -0700123 }
124
125 @Override
126 public boolean equals(Object other) {
127 if (this == other) {
128 return true;
129 }
130
131 if (!(other instanceof ResolvedRoute)) {
132 return false;
133 }
134
135 ResolvedRoute that = (ResolvedRoute) other;
136
Jonathan Hartf2e7a342017-03-20 15:43:21 -0700137 return Objects.equals(this.route, that.route) &&
Charles Chan8fe9f4c2016-10-24 16:46:25 -0700138 Objects.equals(this.nextHopMac, that.nextHopMac) &&
Charles Chan92ca94d2017-03-17 18:05:22 -0700139 Objects.equals(this.nextHopVlan, that.nextHopVlan) &&
Charles Chan8fe9f4c2016-10-24 16:46:25 -0700140 Objects.equals(this.location, that.location);
Jonathan Hart6c2e7962016-04-11 13:54:09 -0700141 }
142
143 @Override
Jonathan Hartfd176612016-04-11 10:42:10 -0700144 public String toString() {
145 return toStringHelper(this)
Jonathan Hartf2e7a342017-03-20 15:43:21 -0700146 .add("route", route)
Jonathan Hartfd176612016-04-11 10:42:10 -0700147 .add("nextHopMac", nextHopMac)
Charles Chan92ca94d2017-03-17 18:05:22 -0700148 .add("nextHopVlan", nextHopVlan)
Charles Chan8fe9f4c2016-10-24 16:46:25 -0700149 .add("location", location)
Jonathan Hartfd176612016-04-11 10:42:10 -0700150 .toString();
151 }
Jonathan Hart7d7e2f52016-03-29 16:22:49 -0700152}