Jonathan Hart | fd17661 | 2016-04-11 10:42:10 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 0a4e674 | 2016-09-15 23:03:10 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Laboratory |
Jonathan Hart | fd17661 | 2016-04-11 10:42:10 -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.MacAddress; |
Charles Chan | c78a098 | 2016-11-09 16:52:11 -0800 | [diff] [blame] | 21 | import org.onosproject.net.ConnectPoint; |
Jonathan Hart | fd17661 | 2016-04-11 10:42:10 -0700 | [diff] [blame] | 22 | |
| 23 | import java.util.Objects; |
| 24 | |
| 25 | import static com.google.common.base.MoreObjects.toStringHelper; |
| 26 | |
| 27 | /** |
| 28 | * Describes a routing next hop. |
| 29 | */ |
| 30 | public class NextHop { |
| 31 | |
| 32 | private final IpAddress ip; |
Charles Chan | c78a098 | 2016-11-09 16:52:11 -0800 | [diff] [blame] | 33 | private final NextHopData nextHopData; |
Jonathan Hart | fd17661 | 2016-04-11 10:42:10 -0700 | [diff] [blame] | 34 | |
| 35 | /** |
| 36 | * Creates a new next hop. |
| 37 | * |
| 38 | * @param ip IP address |
Charles Chan | c78a098 | 2016-11-09 16:52:11 -0800 | [diff] [blame] | 39 | * @param nextHopData Next hop data |
Jonathan Hart | fd17661 | 2016-04-11 10:42:10 -0700 | [diff] [blame] | 40 | */ |
Charles Chan | c78a098 | 2016-11-09 16:52:11 -0800 | [diff] [blame] | 41 | public NextHop(IpAddress ip, NextHopData nextHopData) { |
Jonathan Hart | fd17661 | 2016-04-11 10:42:10 -0700 | [diff] [blame] | 42 | this.ip = ip; |
Charles Chan | c78a098 | 2016-11-09 16:52:11 -0800 | [diff] [blame] | 43 | this.nextHopData = nextHopData; |
Jonathan Hart | fd17661 | 2016-04-11 10:42:10 -0700 | [diff] [blame] | 44 | } |
| 45 | |
| 46 | /** |
| 47 | * Returns the IP address of the next hop. |
| 48 | * |
| 49 | * @return IP address |
| 50 | */ |
| 51 | public IpAddress ip() { |
| 52 | return ip; |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * Returns the MAC address of the next hop. |
| 57 | * |
| 58 | * @return MAC address |
| 59 | */ |
| 60 | public MacAddress mac() { |
Charles Chan | c78a098 | 2016-11-09 16:52:11 -0800 | [diff] [blame] | 61 | return nextHopData.mac(); |
| 62 | } |
| 63 | |
| 64 | /** |
| 65 | * Returns the location of the next hop. |
| 66 | * |
| 67 | * @return Connect point |
| 68 | */ |
| 69 | public ConnectPoint location() { |
| 70 | return nextHopData.location(); |
Jonathan Hart | fd17661 | 2016-04-11 10:42:10 -0700 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | @Override |
| 74 | public int hashCode() { |
Charles Chan | c78a098 | 2016-11-09 16:52:11 -0800 | [diff] [blame] | 75 | return Objects.hash(ip, nextHopData); |
Jonathan Hart | fd17661 | 2016-04-11 10:42:10 -0700 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | @Override |
| 79 | public boolean equals(Object other) { |
| 80 | if (this == other) { |
| 81 | return true; |
| 82 | } |
| 83 | |
| 84 | if (!(other instanceof NextHop)) { |
| 85 | return false; |
| 86 | } |
| 87 | |
| 88 | NextHop that = (NextHop) other; |
| 89 | |
HIGUCHI Yuta | 0a011be | 2016-05-03 14:52:03 -0700 | [diff] [blame] | 90 | return Objects.equals(this.ip, that.ip) && |
Charles Chan | c78a098 | 2016-11-09 16:52:11 -0800 | [diff] [blame] | 91 | Objects.equals(this.nextHopData, that.nextHopData); |
Jonathan Hart | fd17661 | 2016-04-11 10:42:10 -0700 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | @Override |
| 95 | public String toString() { |
| 96 | return toStringHelper(this) |
| 97 | .add("ip", ip) |
Charles Chan | c78a098 | 2016-11-09 16:52:11 -0800 | [diff] [blame] | 98 | .add("nextHopData", nextHopData) |
Jonathan Hart | fd17661 | 2016-04-11 10:42:10 -0700 | [diff] [blame] | 99 | .toString(); |
| 100 | } |
| 101 | } |