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