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; |
Jonathan Hart | 7d7e2f5 | 2016-03-29 16:22:49 -0700 | [diff] [blame] | 23 | |
Jonathan Hart | 6c2e796 | 2016-04-11 13:54:09 -0700 | [diff] [blame] | 24 | import java.util.Objects; |
| 25 | |
Jonathan Hart | fd17661 | 2016-04-11 10:42:10 -0700 | [diff] [blame] | 26 | import static com.google.common.base.MoreObjects.toStringHelper; |
| 27 | |
Jonathan Hart | 7d7e2f5 | 2016-03-29 16:22:49 -0700 | [diff] [blame] | 28 | /** |
| 29 | * Represents a route with the next hop MAC address resolved. |
| 30 | */ |
Charles Chan | 9640c81 | 2017-08-23 13:55:39 -0700 | [diff] [blame] | 31 | // TODO Remove location from ResolvedRoute |
Jonathan Hart | 7d7e2f5 | 2016-03-29 16:22:49 -0700 | [diff] [blame] | 32 | public class ResolvedRoute { |
| 33 | |
Jonathan Hart | f2e7a34 | 2017-03-20 15:43:21 -0700 | [diff] [blame] | 34 | private final Route route; |
Jonathan Hart | 7d7e2f5 | 2016-03-29 16:22:49 -0700 | [diff] [blame] | 35 | private final MacAddress nextHopMac; |
Charles Chan | 92ca94d | 2017-03-17 18:05:22 -0700 | [diff] [blame] | 36 | private final VlanId nextHopVlan; |
Charles Chan | 9640c81 | 2017-08-23 13:55:39 -0700 | [diff] [blame] | 37 | |
| 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 Chan | 9640c81 | 2017-08-23 13:55:39 -0700 | [diff] [blame] | 59 | } |
| 60 | |
Charles Chan | 92ca94d | 2017-03-17 18:05:22 -0700 | [diff] [blame] | 61 | /** |
Jonathan Hart | f2e7a34 | 2017-03-20 15:43:21 -0700 | [diff] [blame] | 62 | * Returns the original route. |
Charles Chan | 92ca94d | 2017-03-17 18:05:22 -0700 | [diff] [blame] | 63 | * |
Jonathan Hart | f2e7a34 | 2017-03-20 15:43:21 -0700 | [diff] [blame] | 64 | * @return route |
Charles Chan | 92ca94d | 2017-03-17 18:05:22 -0700 | [diff] [blame] | 65 | */ |
Jonathan Hart | f2e7a34 | 2017-03-20 15:43:21 -0700 | [diff] [blame] | 66 | public Route route() { |
| 67 | return route; |
Jonathan Hart | 7d7e2f5 | 2016-03-29 16:22:49 -0700 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | /** |
| 71 | * Returns the IP prefix. |
| 72 | * |
| 73 | * @return IP prefix |
| 74 | */ |
| 75 | public IpPrefix prefix() { |
Jonathan Hart | f2e7a34 | 2017-03-20 15:43:21 -0700 | [diff] [blame] | 76 | return route.prefix(); |
Jonathan Hart | 7d7e2f5 | 2016-03-29 16:22:49 -0700 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | /** |
| 80 | * Returns the next hop IP address. |
| 81 | * |
| 82 | * @return IP address |
| 83 | */ |
| 84 | public IpAddress nextHop() { |
Jonathan Hart | f2e7a34 | 2017-03-20 15:43:21 -0700 | [diff] [blame] | 85 | return route.nextHop(); |
Jonathan Hart | 7d7e2f5 | 2016-03-29 16:22:49 -0700 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | /** |
| 89 | * Returns the next hop MAC address. |
| 90 | * |
| 91 | * @return MAC address |
| 92 | */ |
| 93 | public MacAddress nextHopMac() { |
| 94 | return nextHopMac; |
| 95 | } |
Jonathan Hart | fd17661 | 2016-04-11 10:42:10 -0700 | [diff] [blame] | 96 | |
Charles Chan | 8fe9f4c | 2016-10-24 16:46:25 -0700 | [diff] [blame] | 97 | /** |
Charles Chan | 92ca94d | 2017-03-17 18:05:22 -0700 | [diff] [blame] | 98 | * Returns the next hop VLAN ID. |
| 99 | * |
| 100 | * @return VLAN ID |
| 101 | */ |
| 102 | public VlanId nextHopVlan() { |
| 103 | return nextHopVlan; |
| 104 | } |
| 105 | |
Jonathan Hart | fd17661 | 2016-04-11 10:42:10 -0700 | [diff] [blame] | 106 | @Override |
Jonathan Hart | 6c2e796 | 2016-04-11 13:54:09 -0700 | [diff] [blame] | 107 | public int hashCode() { |
Charles Chan | 9bc6074 | 2017-11-19 13:59:59 -0800 | [diff] [blame] | 108 | return Objects.hash(route, nextHopMac, nextHopVlan); |
Jonathan Hart | 6c2e796 | 2016-04-11 13:54:09 -0700 | [diff] [blame] | 109 | } |
| 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 Hart | f2e7a34 | 2017-03-20 15:43:21 -0700 | [diff] [blame] | 123 | return Objects.equals(this.route, that.route) && |
Charles Chan | 8fe9f4c | 2016-10-24 16:46:25 -0700 | [diff] [blame] | 124 | Objects.equals(this.nextHopMac, that.nextHopMac) && |
Charles Chan | 9bc6074 | 2017-11-19 13:59:59 -0800 | [diff] [blame] | 125 | Objects.equals(this.nextHopVlan, that.nextHopVlan); |
Jonathan Hart | 6c2e796 | 2016-04-11 13:54:09 -0700 | [diff] [blame] | 126 | } |
| 127 | |
| 128 | @Override |
Jonathan Hart | fd17661 | 2016-04-11 10:42:10 -0700 | [diff] [blame] | 129 | public String toString() { |
| 130 | return toStringHelper(this) |
Jonathan Hart | f2e7a34 | 2017-03-20 15:43:21 -0700 | [diff] [blame] | 131 | .add("route", route) |
Jonathan Hart | fd17661 | 2016-04-11 10:42:10 -0700 | [diff] [blame] | 132 | .add("nextHopMac", nextHopMac) |
Charles Chan | 92ca94d | 2017-03-17 18:05:22 -0700 | [diff] [blame] | 133 | .add("nextHopVlan", nextHopVlan) |
Jonathan Hart | fd17661 | 2016-04-11 10:42:10 -0700 | [diff] [blame] | 134 | .toString(); |
| 135 | } |
Jonathan Hart | 7d7e2f5 | 2016-03-29 16:22:49 -0700 | [diff] [blame] | 136 | } |