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