Jonathan Hart | 7d7e2f5 | 2016-03-29 16:22:49 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
Jonathan Hart | 7d7e2f5 | 2016-03-29 16:22:49 -0700 | [diff] [blame] | 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 | |
Ray Milkey | 69ec871 | 2017-08-08 13:00:43 -0700 | [diff] [blame] | 17 | package org.onosproject.routeservice; |
Jonathan Hart | 7d7e2f5 | 2016-03-29 16:22:49 -0700 | [diff] [blame] | 18 | |
| 19 | import org.onlab.packet.IpAddress; |
| 20 | import org.onlab.packet.IpPrefix; |
| 21 | import org.onlab.packet.MacAddress; |
Charles Chan | 92ca94d | 2017-03-17 18:05:22 -0700 | [diff] [blame] | 22 | import org.onlab.packet.VlanId; |
Charles Chan | 8fe9f4c | 2016-10-24 16:46:25 -0700 | [diff] [blame] | 23 | import org.onosproject.net.ConnectPoint; |
Jonathan Hart | 7d7e2f5 | 2016-03-29 16:22:49 -0700 | [diff] [blame] | 24 | |
Jonathan Hart | 6c2e796 | 2016-04-11 13:54:09 -0700 | [diff] [blame] | 25 | import java.util.Objects; |
| 26 | |
Jonathan Hart | fd17661 | 2016-04-11 10:42:10 -0700 | [diff] [blame] | 27 | import static com.google.common.base.MoreObjects.toStringHelper; |
| 28 | |
Jonathan Hart | 7d7e2f5 | 2016-03-29 16:22:49 -0700 | [diff] [blame] | 29 | /** |
| 30 | * Represents a route with the next hop MAC address resolved. |
| 31 | */ |
Charles Chan | 9640c81 | 2017-08-23 13:55:39 -0700 | [diff] [blame] | 32 | // TODO Remove location from ResolvedRoute |
Jonathan Hart | 7d7e2f5 | 2016-03-29 16:22:49 -0700 | [diff] [blame] | 33 | public class ResolvedRoute { |
| 34 | |
Jonathan Hart | f2e7a34 | 2017-03-20 15:43:21 -0700 | [diff] [blame] | 35 | private final Route route; |
Jonathan Hart | 7d7e2f5 | 2016-03-29 16:22:49 -0700 | [diff] [blame] | 36 | private final MacAddress nextHopMac; |
Charles Chan | 92ca94d | 2017-03-17 18:05:22 -0700 | [diff] [blame] | 37 | private final VlanId nextHopVlan; |
Charles Chan | 8fe9f4c | 2016-10-24 16:46:25 -0700 | [diff] [blame] | 38 | private final ConnectPoint location; |
Jonathan Hart | 7d7e2f5 | 2016-03-29 16:22:49 -0700 | [diff] [blame] | 39 | |
| 40 | /** |
| 41 | * Creates a new resolved route. |
| 42 | * |
| 43 | * @param route input route |
| 44 | * @param nextHopMac next hop MAC address |
Charles Chan | 8fe9f4c | 2016-10-24 16:46:25 -0700 | [diff] [blame] | 45 | * @param location connect point where the next hop connects to |
Charles Chan | 9640c81 | 2017-08-23 13:55:39 -0700 | [diff] [blame] | 46 | * @deprecated in 1.11 ("Loon") |
Jonathan Hart | 7d7e2f5 | 2016-03-29 16:22:49 -0700 | [diff] [blame] | 47 | */ |
Charles Chan | 9640c81 | 2017-08-23 13:55:39 -0700 | [diff] [blame] | 48 | @Deprecated |
Charles Chan | 8fe9f4c | 2016-10-24 16:46:25 -0700 | [diff] [blame] | 49 | public ResolvedRoute(Route route, MacAddress nextHopMac, ConnectPoint location) { |
Charles Chan | 92ca94d | 2017-03-17 18:05:22 -0700 | [diff] [blame] | 50 | this(route, nextHopMac, VlanId.NONE, location); |
Jonathan Hart | 7d7e2f5 | 2016-03-29 16:22:49 -0700 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | /** |
| 54 | * Creates a new resolved route. |
| 55 | * |
Charles Chan | 92ca94d | 2017-03-17 18:05:22 -0700 | [diff] [blame] | 56 | * @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 Chan | 9640c81 | 2017-08-23 13:55:39 -0700 | [diff] [blame] | 60 | * @deprecated in 1.11 ("Loon") |
Charles Chan | 92ca94d | 2017-03-17 18:05:22 -0700 | [diff] [blame] | 61 | */ |
Charles Chan | 9640c81 | 2017-08-23 13:55:39 -0700 | [diff] [blame] | 62 | @Deprecated |
Charles Chan | 92ca94d | 2017-03-17 18:05:22 -0700 | [diff] [blame] | 63 | public ResolvedRoute(Route route, MacAddress nextHopMac, VlanId nextHopVlan, |
| 64 | ConnectPoint location) { |
Jonathan Hart | f2e7a34 | 2017-03-20 15:43:21 -0700 | [diff] [blame] | 65 | this.route = route; |
Charles Chan | 92ca94d | 2017-03-17 18:05:22 -0700 | [diff] [blame] | 66 | this.nextHopMac = nextHopMac; |
| 67 | this.nextHopVlan = nextHopVlan; |
| 68 | this.location = location; |
| 69 | } |
| 70 | |
Charles Chan | 9640c81 | 2017-08-23 13:55:39 -0700 | [diff] [blame] | 71 | |
| 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 Chan | 92ca94d | 2017-03-17 18:05:22 -0700 | [diff] [blame] | 96 | /** |
Jonathan Hart | f2e7a34 | 2017-03-20 15:43:21 -0700 | [diff] [blame] | 97 | * Returns the original route. |
Charles Chan | 92ca94d | 2017-03-17 18:05:22 -0700 | [diff] [blame] | 98 | * |
Jonathan Hart | f2e7a34 | 2017-03-20 15:43:21 -0700 | [diff] [blame] | 99 | * @return route |
Charles Chan | 92ca94d | 2017-03-17 18:05:22 -0700 | [diff] [blame] | 100 | */ |
Jonathan Hart | f2e7a34 | 2017-03-20 15:43:21 -0700 | [diff] [blame] | 101 | public Route route() { |
| 102 | return route; |
Jonathan Hart | 7d7e2f5 | 2016-03-29 16:22:49 -0700 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | /** |
| 106 | * Returns the IP prefix. |
| 107 | * |
| 108 | * @return IP prefix |
| 109 | */ |
| 110 | public IpPrefix prefix() { |
Jonathan Hart | f2e7a34 | 2017-03-20 15:43:21 -0700 | [diff] [blame] | 111 | return route.prefix(); |
Jonathan Hart | 7d7e2f5 | 2016-03-29 16:22:49 -0700 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | /** |
| 115 | * Returns the next hop IP address. |
| 116 | * |
| 117 | * @return IP address |
| 118 | */ |
| 119 | public IpAddress nextHop() { |
Jonathan Hart | f2e7a34 | 2017-03-20 15:43:21 -0700 | [diff] [blame] | 120 | return route.nextHop(); |
Jonathan Hart | 7d7e2f5 | 2016-03-29 16:22:49 -0700 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | /** |
| 124 | * Returns the next hop MAC address. |
| 125 | * |
| 126 | * @return MAC address |
| 127 | */ |
| 128 | public MacAddress nextHopMac() { |
| 129 | return nextHopMac; |
| 130 | } |
Jonathan Hart | fd17661 | 2016-04-11 10:42:10 -0700 | [diff] [blame] | 131 | |
Charles Chan | 8fe9f4c | 2016-10-24 16:46:25 -0700 | [diff] [blame] | 132 | /** |
Charles Chan | 92ca94d | 2017-03-17 18:05:22 -0700 | [diff] [blame] | 133 | * Returns the next hop VLAN ID. |
| 134 | * |
| 135 | * @return VLAN ID |
| 136 | */ |
| 137 | public VlanId nextHopVlan() { |
| 138 | return nextHopVlan; |
| 139 | } |
| 140 | |
| 141 | /** |
Charles Chan | 8fe9f4c | 2016-10-24 16:46:25 -0700 | [diff] [blame] | 142 | * Returns the next hop location. |
| 143 | * |
| 144 | * @return connect point where the next hop attaches to |
Charles Chan | 9640c81 | 2017-08-23 13:55:39 -0700 | [diff] [blame] | 145 | * @deprecated in 1.11 ("Loon") |
Charles Chan | 8fe9f4c | 2016-10-24 16:46:25 -0700 | [diff] [blame] | 146 | */ |
Charles Chan | 9640c81 | 2017-08-23 13:55:39 -0700 | [diff] [blame] | 147 | @Deprecated |
Charles Chan | 8fe9f4c | 2016-10-24 16:46:25 -0700 | [diff] [blame] | 148 | public ConnectPoint location() { |
| 149 | return location; |
| 150 | } |
| 151 | |
Jonathan Hart | fd17661 | 2016-04-11 10:42:10 -0700 | [diff] [blame] | 152 | @Override |
Jonathan Hart | 6c2e796 | 2016-04-11 13:54:09 -0700 | [diff] [blame] | 153 | public int hashCode() { |
Charles Chan | 9bc6074 | 2017-11-19 13:59:59 -0800 | [diff] [blame] | 154 | return Objects.hash(route, nextHopMac, nextHopVlan); |
Jonathan Hart | 6c2e796 | 2016-04-11 13:54:09 -0700 | [diff] [blame] | 155 | } |
| 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 Hart | f2e7a34 | 2017-03-20 15:43:21 -0700 | [diff] [blame] | 169 | return Objects.equals(this.route, that.route) && |
Charles Chan | 8fe9f4c | 2016-10-24 16:46:25 -0700 | [diff] [blame] | 170 | Objects.equals(this.nextHopMac, that.nextHopMac) && |
Charles Chan | 9bc6074 | 2017-11-19 13:59:59 -0800 | [diff] [blame] | 171 | Objects.equals(this.nextHopVlan, that.nextHopVlan); |
Jonathan Hart | 6c2e796 | 2016-04-11 13:54:09 -0700 | [diff] [blame] | 172 | } |
| 173 | |
| 174 | @Override |
Jonathan Hart | fd17661 | 2016-04-11 10:42:10 -0700 | [diff] [blame] | 175 | public String toString() { |
| 176 | return toStringHelper(this) |
Jonathan Hart | f2e7a34 | 2017-03-20 15:43:21 -0700 | [diff] [blame] | 177 | .add("route", route) |
Jonathan Hart | fd17661 | 2016-04-11 10:42:10 -0700 | [diff] [blame] | 178 | .add("nextHopMac", nextHopMac) |
Charles Chan | 92ca94d | 2017-03-17 18:05:22 -0700 | [diff] [blame] | 179 | .add("nextHopVlan", nextHopVlan) |
Jonathan Hart | fd17661 | 2016-04-11 10:42:10 -0700 | [diff] [blame] | 180 | .toString(); |
| 181 | } |
Jonathan Hart | 7d7e2f5 | 2016-03-29 16:22:49 -0700 | [diff] [blame] | 182 | } |