Jonathan Hart | 7d7e2f5 | 2016-03-29 16:22:49 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Laboratory |
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 | |
| 17 | package org.onosproject.incubator.net.routing; |
| 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 | */ |
| 32 | public class ResolvedRoute { |
| 33 | |
| 34 | private final IpPrefix prefix; |
| 35 | private final IpAddress nextHop; |
| 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 |
Jonathan Hart | 7d7e2f5 | 2016-03-29 16:22:49 -0700 | [diff] [blame] | 46 | */ |
Charles Chan | 8fe9f4c | 2016-10-24 16:46:25 -0700 | [diff] [blame] | 47 | public ResolvedRoute(Route route, MacAddress nextHopMac, ConnectPoint location) { |
Charles Chan | 92ca94d | 2017-03-17 18:05:22 -0700 | [diff] [blame^] | 48 | this(route, nextHopMac, VlanId.NONE, location); |
Jonathan Hart | 7d7e2f5 | 2016-03-29 16:22:49 -0700 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | /** |
| 52 | * Creates a new resolved route. |
| 53 | * |
| 54 | * @param prefix route prefix |
| 55 | * @param nextHop route next hop IP address |
| 56 | * @param nextHopMac next hop MAC address |
Charles Chan | 8fe9f4c | 2016-10-24 16:46:25 -0700 | [diff] [blame] | 57 | * @param location connect point where the next hop connects to |
Jonathan Hart | 7d7e2f5 | 2016-03-29 16:22:49 -0700 | [diff] [blame] | 58 | */ |
Charles Chan | 8fe9f4c | 2016-10-24 16:46:25 -0700 | [diff] [blame] | 59 | public ResolvedRoute(IpPrefix prefix, IpAddress nextHop, MacAddress nextHopMac, |
| 60 | ConnectPoint location) { |
Charles Chan | 92ca94d | 2017-03-17 18:05:22 -0700 | [diff] [blame^] | 61 | this(prefix, nextHop, nextHopMac, VlanId.NONE, location); |
| 62 | } |
| 63 | |
| 64 | /** |
| 65 | * Creates a new resolved route. |
| 66 | * |
| 67 | * @param route input route |
| 68 | * @param nextHopMac next hop MAC address |
| 69 | * @param nextHopVlan next hop VLAN ID |
| 70 | * @param location connect point where the next hop connects to |
| 71 | */ |
| 72 | public ResolvedRoute(Route route, MacAddress nextHopMac, VlanId nextHopVlan, |
| 73 | ConnectPoint location) { |
| 74 | this.prefix = route.prefix(); |
| 75 | this.nextHop = route.nextHop(); |
| 76 | this.nextHopMac = nextHopMac; |
| 77 | this.nextHopVlan = nextHopVlan; |
| 78 | this.location = location; |
| 79 | } |
| 80 | |
| 81 | /** |
| 82 | * Creates a new resolved route. |
| 83 | * |
| 84 | * @param prefix route prefix |
| 85 | * @param nextHop route next hop IP address |
| 86 | * @param nextHopMac next hop MAC address |
| 87 | * @param nextHopVlan next hop VLAN address |
| 88 | * @param location connect point where the next hop connects to |
| 89 | */ |
| 90 | public ResolvedRoute(IpPrefix prefix, IpAddress nextHop, MacAddress nextHopMac, |
| 91 | VlanId nextHopVlan, ConnectPoint location) { |
Jonathan Hart | 7d7e2f5 | 2016-03-29 16:22:49 -0700 | [diff] [blame] | 92 | this.prefix = prefix; |
| 93 | this.nextHop = nextHop; |
| 94 | this.nextHopMac = nextHopMac; |
Charles Chan | 92ca94d | 2017-03-17 18:05:22 -0700 | [diff] [blame^] | 95 | this.nextHopVlan = nextHopVlan; |
Charles Chan | 8fe9f4c | 2016-10-24 16:46:25 -0700 | [diff] [blame] | 96 | this.location = location; |
Jonathan Hart | 7d7e2f5 | 2016-03-29 16:22:49 -0700 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | /** |
| 100 | * Returns the IP prefix. |
| 101 | * |
| 102 | * @return IP prefix |
| 103 | */ |
| 104 | public IpPrefix prefix() { |
| 105 | return prefix; |
| 106 | } |
| 107 | |
| 108 | /** |
| 109 | * Returns the next hop IP address. |
| 110 | * |
| 111 | * @return IP address |
| 112 | */ |
| 113 | public IpAddress nextHop() { |
| 114 | return nextHop; |
| 115 | } |
| 116 | |
| 117 | /** |
| 118 | * Returns the next hop MAC address. |
| 119 | * |
| 120 | * @return MAC address |
| 121 | */ |
| 122 | public MacAddress nextHopMac() { |
| 123 | return nextHopMac; |
| 124 | } |
Jonathan Hart | fd17661 | 2016-04-11 10:42:10 -0700 | [diff] [blame] | 125 | |
Charles Chan | 8fe9f4c | 2016-10-24 16:46:25 -0700 | [diff] [blame] | 126 | /** |
Charles Chan | 92ca94d | 2017-03-17 18:05:22 -0700 | [diff] [blame^] | 127 | * Returns the next hop VLAN ID. |
| 128 | * |
| 129 | * @return VLAN ID |
| 130 | */ |
| 131 | public VlanId nextHopVlan() { |
| 132 | return nextHopVlan; |
| 133 | } |
| 134 | |
| 135 | /** |
Charles Chan | 8fe9f4c | 2016-10-24 16:46:25 -0700 | [diff] [blame] | 136 | * Returns the next hop location. |
| 137 | * |
| 138 | * @return connect point where the next hop attaches to |
| 139 | */ |
| 140 | public ConnectPoint location() { |
| 141 | return location; |
| 142 | } |
| 143 | |
Jonathan Hart | fd17661 | 2016-04-11 10:42:10 -0700 | [diff] [blame] | 144 | @Override |
Jonathan Hart | 6c2e796 | 2016-04-11 13:54:09 -0700 | [diff] [blame] | 145 | public int hashCode() { |
Charles Chan | 92ca94d | 2017-03-17 18:05:22 -0700 | [diff] [blame^] | 146 | return Objects.hash(prefix, nextHop, nextHopMac, nextHopVlan, location); |
Jonathan Hart | 6c2e796 | 2016-04-11 13:54:09 -0700 | [diff] [blame] | 147 | } |
| 148 | |
| 149 | @Override |
| 150 | public boolean equals(Object other) { |
| 151 | if (this == other) { |
| 152 | return true; |
| 153 | } |
| 154 | |
| 155 | if (!(other instanceof ResolvedRoute)) { |
| 156 | return false; |
| 157 | } |
| 158 | |
| 159 | ResolvedRoute that = (ResolvedRoute) other; |
| 160 | |
| 161 | return Objects.equals(this.prefix, that.prefix) && |
| 162 | Objects.equals(this.nextHop, that.nextHop) && |
Charles Chan | 8fe9f4c | 2016-10-24 16:46:25 -0700 | [diff] [blame] | 163 | Objects.equals(this.nextHopMac, that.nextHopMac) && |
Charles Chan | 92ca94d | 2017-03-17 18:05:22 -0700 | [diff] [blame^] | 164 | Objects.equals(this.nextHopVlan, that.nextHopVlan) && |
Charles Chan | 8fe9f4c | 2016-10-24 16:46:25 -0700 | [diff] [blame] | 165 | Objects.equals(this.location, that.location); |
Jonathan Hart | 6c2e796 | 2016-04-11 13:54:09 -0700 | [diff] [blame] | 166 | } |
| 167 | |
| 168 | @Override |
Jonathan Hart | fd17661 | 2016-04-11 10:42:10 -0700 | [diff] [blame] | 169 | public String toString() { |
| 170 | return toStringHelper(this) |
| 171 | .add("prefix", prefix) |
| 172 | .add("nextHop", nextHop) |
| 173 | .add("nextHopMac", nextHopMac) |
Charles Chan | 92ca94d | 2017-03-17 18:05:22 -0700 | [diff] [blame^] | 174 | .add("nextHopVlan", nextHopVlan) |
Charles Chan | 8fe9f4c | 2016-10-24 16:46:25 -0700 | [diff] [blame] | 175 | .add("location", location) |
Jonathan Hart | fd17661 | 2016-04-11 10:42:10 -0700 | [diff] [blame] | 176 | .toString(); |
| 177 | } |
Jonathan Hart | 7d7e2f5 | 2016-03-29 16:22:49 -0700 | [diff] [blame] | 178 | } |