Jonathan Hart | f582920 | 2015-02-12 09:37:02 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 Open Networking Laboratory |
| 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 | package org.onosproject.bgprouter; |
| 17 | |
| 18 | import com.google.common.base.MoreObjects; |
| 19 | import org.onlab.packet.IpAddress; |
| 20 | import org.onlab.packet.MacAddress; |
Jonathan Hart | 7baba07 | 2015-02-23 14:27:59 -0800 | [diff] [blame] | 21 | import org.onosproject.net.group.GroupKey; |
Jonathan Hart | f582920 | 2015-02-12 09:37:02 -0800 | [diff] [blame] | 22 | |
| 23 | import java.util.Objects; |
| 24 | |
| 25 | /** |
Jonathan Hart | 7baba07 | 2015-02-23 14:27:59 -0800 | [diff] [blame] | 26 | * Represents a next hop for routing, whose MAC address has already been resolved. |
Jonathan Hart | f582920 | 2015-02-12 09:37:02 -0800 | [diff] [blame] | 27 | */ |
| 28 | public class NextHop { |
| 29 | |
| 30 | private final IpAddress ip; |
| 31 | private final MacAddress mac; |
Jonathan Hart | 7baba07 | 2015-02-23 14:27:59 -0800 | [diff] [blame] | 32 | private final GroupKey group; |
Jonathan Hart | f582920 | 2015-02-12 09:37:02 -0800 | [diff] [blame] | 33 | |
Jonathan Hart | 7baba07 | 2015-02-23 14:27:59 -0800 | [diff] [blame] | 34 | /** |
| 35 | * Creates a new next hop. |
| 36 | * |
| 37 | * @param ip next hop's IP address |
| 38 | * @param mac next hop's MAC address |
| 39 | * @param group next hop's group |
| 40 | */ |
| 41 | public NextHop(IpAddress ip, MacAddress mac, GroupKey group) { |
Jonathan Hart | f582920 | 2015-02-12 09:37:02 -0800 | [diff] [blame] | 42 | this.ip = ip; |
| 43 | this.mac = mac; |
Jonathan Hart | 7baba07 | 2015-02-23 14:27:59 -0800 | [diff] [blame] | 44 | this.group = group; |
Jonathan Hart | f582920 | 2015-02-12 09:37:02 -0800 | [diff] [blame] | 45 | } |
| 46 | |
Jonathan Hart | 7baba07 | 2015-02-23 14:27:59 -0800 | [diff] [blame] | 47 | /** |
| 48 | * Returns the next hop's IP address. |
| 49 | * |
| 50 | * @return next hop's IP address |
| 51 | */ |
Jonathan Hart | f582920 | 2015-02-12 09:37:02 -0800 | [diff] [blame] | 52 | public IpAddress ip() { |
| 53 | return ip; |
| 54 | } |
| 55 | |
Jonathan Hart | 7baba07 | 2015-02-23 14:27:59 -0800 | [diff] [blame] | 56 | /** |
| 57 | * Returns the next hop's MAC address. |
| 58 | * |
| 59 | * @return next hop's MAC address |
| 60 | */ |
Jonathan Hart | f582920 | 2015-02-12 09:37:02 -0800 | [diff] [blame] | 61 | public MacAddress mac() { |
| 62 | return mac; |
| 63 | } |
| 64 | |
Jonathan Hart | 7baba07 | 2015-02-23 14:27:59 -0800 | [diff] [blame] | 65 | /** |
| 66 | * Returns the next hop group. |
| 67 | * |
| 68 | * @return group |
| 69 | */ |
| 70 | public GroupKey group() { |
| 71 | return group; |
| 72 | } |
| 73 | |
Jonathan Hart | f582920 | 2015-02-12 09:37:02 -0800 | [diff] [blame] | 74 | @Override |
| 75 | public boolean equals(Object o) { |
| 76 | if (!(o instanceof NextHop)) { |
| 77 | return false; |
| 78 | } |
| 79 | |
| 80 | NextHop that = (NextHop) o; |
| 81 | |
| 82 | return Objects.equals(this.ip, that.ip) && |
Jonathan Hart | 7baba07 | 2015-02-23 14:27:59 -0800 | [diff] [blame] | 83 | Objects.equals(this.mac, that.mac) && |
| 84 | Objects.equals(this.group, that.group); |
Jonathan Hart | f582920 | 2015-02-12 09:37:02 -0800 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | @Override |
| 88 | public int hashCode() { |
Jonathan Hart | 7baba07 | 2015-02-23 14:27:59 -0800 | [diff] [blame] | 89 | return Objects.hash(ip, mac, group); |
Jonathan Hart | f582920 | 2015-02-12 09:37:02 -0800 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | @Override |
| 93 | public String toString() { |
| 94 | return MoreObjects.toStringHelper(getClass()) |
| 95 | .add("ip", ip) |
| 96 | .add("mac", mac) |
Jonathan Hart | 7baba07 | 2015-02-23 14:27:59 -0800 | [diff] [blame] | 97 | .add("group", group) |
Jonathan Hart | f582920 | 2015-02-12 09:37:02 -0800 | [diff] [blame] | 98 | .toString(); |
| 99 | } |
| 100 | } |