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; |
| 22 | |
Jonathan Hart | 6c2e796 | 2016-04-11 13:54:09 -0700 | [diff] [blame] | 23 | import java.util.Objects; |
| 24 | |
Jonathan Hart | fd17661 | 2016-04-11 10:42:10 -0700 | [diff] [blame] | 25 | import static com.google.common.base.MoreObjects.toStringHelper; |
| 26 | |
Jonathan Hart | 7d7e2f5 | 2016-03-29 16:22:49 -0700 | [diff] [blame] | 27 | /** |
| 28 | * Represents a route with the next hop MAC address resolved. |
| 29 | */ |
| 30 | public class ResolvedRoute { |
| 31 | |
| 32 | private final IpPrefix prefix; |
| 33 | private final IpAddress nextHop; |
| 34 | private final MacAddress nextHopMac; |
| 35 | |
| 36 | /** |
| 37 | * Creates a new resolved route. |
| 38 | * |
| 39 | * @param route input route |
| 40 | * @param nextHopMac next hop MAC address |
| 41 | */ |
| 42 | public ResolvedRoute(Route route, MacAddress nextHopMac) { |
| 43 | this.prefix = route.prefix(); |
| 44 | this.nextHop = route.nextHop(); |
| 45 | this.nextHopMac = nextHopMac; |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * Creates a new resolved route. |
| 50 | * |
| 51 | * @param prefix route prefix |
| 52 | * @param nextHop route next hop IP address |
| 53 | * @param nextHopMac next hop MAC address |
| 54 | */ |
| 55 | public ResolvedRoute(IpPrefix prefix, IpAddress nextHop, MacAddress nextHopMac) { |
| 56 | this.prefix = prefix; |
| 57 | this.nextHop = nextHop; |
| 58 | this.nextHopMac = nextHopMac; |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * Returns the IP prefix. |
| 63 | * |
| 64 | * @return IP prefix |
| 65 | */ |
| 66 | public IpPrefix prefix() { |
| 67 | return prefix; |
| 68 | } |
| 69 | |
| 70 | /** |
| 71 | * Returns the next hop IP address. |
| 72 | * |
| 73 | * @return IP address |
| 74 | */ |
| 75 | public IpAddress nextHop() { |
| 76 | return nextHop; |
| 77 | } |
| 78 | |
| 79 | /** |
| 80 | * Returns the next hop MAC address. |
| 81 | * |
| 82 | * @return MAC address |
| 83 | */ |
| 84 | public MacAddress nextHopMac() { |
| 85 | return nextHopMac; |
| 86 | } |
Jonathan Hart | fd17661 | 2016-04-11 10:42:10 -0700 | [diff] [blame] | 87 | |
| 88 | @Override |
Jonathan Hart | 6c2e796 | 2016-04-11 13:54:09 -0700 | [diff] [blame] | 89 | public int hashCode() { |
| 90 | return Objects.hash(prefix, nextHop, nextHopMac); |
| 91 | } |
| 92 | |
| 93 | @Override |
| 94 | public boolean equals(Object other) { |
| 95 | if (this == other) { |
| 96 | return true; |
| 97 | } |
| 98 | |
| 99 | if (!(other instanceof ResolvedRoute)) { |
| 100 | return false; |
| 101 | } |
| 102 | |
| 103 | ResolvedRoute that = (ResolvedRoute) other; |
| 104 | |
| 105 | return Objects.equals(this.prefix, that.prefix) && |
| 106 | Objects.equals(this.nextHop, that.nextHop) && |
| 107 | Objects.equals(this.nextHopMac, that.nextHopMac); |
| 108 | } |
| 109 | |
| 110 | @Override |
Jonathan Hart | fd17661 | 2016-04-11 10:42:10 -0700 | [diff] [blame] | 111 | public String toString() { |
| 112 | return toStringHelper(this) |
| 113 | .add("prefix", prefix) |
| 114 | .add("nextHop", nextHop) |
| 115 | .add("nextHopMac", nextHopMac) |
| 116 | .toString(); |
| 117 | } |
Jonathan Hart | 7d7e2f5 | 2016-03-29 16:22:49 -0700 | [diff] [blame] | 118 | } |